当前位置:   article > 正文

题目59 考勤记录(ok)_公司用一个字符串来表示员工的出勤信息: absent:缺勤

公司用一个字符串来表示员工的出勤信息: absent:缺勤

公司用一个字符串来标识员工的出勤信息
absent:    缺勤
late:      迟到
leaveearly:早退
present:   正常上班

现需根据员工出勤信息,判断本次是否能获得出勤奖,
能获得出勤奖的条件如下:
1.缺勤不超过1次
2.没有连续的迟到/早退
3.任意连续7次考勤 缺勤/迟到/早退 不超过3次

输入描述:
用户的考勤数据字符串记录条数  >=1
输入字符串长度 <10000 ;
不存在非法输入
如:
2
present
present absent present present leaveearly present absent

输出描述:
根据考勤数据字符串
如果能得到考勤奖输出true否则输出false
对于输出示例的结果应为
true false

示例一:
输入:
2
present
present present

输出:
true true

示例二
输入:
2
present
present absent present present leaveearly present absent
输出:
true false
 

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. enum {
  5. NUM_ABSENT,
  6. NUM_LATE,
  7. NUM_LEAVEEARLY,
  8. NUM_PRESENT
  9. };
  10. void IsQuan(char *s)
  11. {
  12. char *token = NULL;
  13. int list[256] = {0};
  14. int idx = 0, i, j;
  15. int absent = 0;
  16. /*
  17. absent: 缺勤
  18. late: 迟到
  19. leaveearly:早退
  20. present: 正常上班
  21. */
  22. token = strtok(s, " ");
  23. while (token != NULL) {
  24. //printf("%s\n", token);
  25. if (strcmp(token, "absent") == 0) {
  26. list[idx] = NUM_ABSENT;
  27. absent++;
  28. if (absent > 1) {
  29. printf("false\n");
  30. return;
  31. }
  32. } else if (strcmp(token, "late") == 0) {
  33. list[idx] = NUM_LATE;
  34. } else if (strcmp(token, "leaveearly") == 0) {
  35. list[idx] = NUM_LEAVEEARLY;
  36. } else if (strcmp(token, "present") == 0) {
  37. list[idx] = NUM_PRESENT;
  38. }
  39. idx++;
  40. token = strtok(NULL, " ");
  41. }
  42. int count;
  43. for (i = 0; i < idx; i++) {
  44. count = 0;
  45. for (j = i ;j < i + 7 && i + 7 <=idx; j++) {
  46. if (list[j] == NUM_ABSENT || list[j] == NUM_LATE || list[j] == NUM_LEAVEEARLY) {
  47. count++;
  48. }
  49. }
  50. if (count > 3) {
  51. printf("false\n");
  52. return;
  53. }
  54. }
  55. printf("true\n");
  56. }
  57. int main()
  58. {
  59. int n, i;
  60. char input[32] = {0};
  61. scanf("%d", &n);
  62. getchar();
  63. for (i = 0; i < n; i++) {
  64. memset(input, 0, sizeof(input));
  65. gets(input);
  66. // printf("%s\n", input);
  67. IsQuan(input);
  68. }
  69. return 0;
  70. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/431830
推荐阅读
相关标签
  

闽ICP备14008679号