赞
踩
公司用一个字符串来标识员工的出勤信息
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
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- enum {
- NUM_ABSENT,
- NUM_LATE,
- NUM_LEAVEEARLY,
- NUM_PRESENT
- };
-
- void IsQuan(char *s)
- {
- char *token = NULL;
- int list[256] = {0};
- int idx = 0, i, j;
- int absent = 0;
- /*
- absent: 缺勤
- late: 迟到
- leaveearly:早退
- present: 正常上班
- */
- token = strtok(s, " ");
- while (token != NULL) {
- //printf("%s\n", token);
- if (strcmp(token, "absent") == 0) {
- list[idx] = NUM_ABSENT;
- absent++;
- if (absent > 1) {
- printf("false\n");
- return;
- }
- } else if (strcmp(token, "late") == 0) {
- list[idx] = NUM_LATE;
- } else if (strcmp(token, "leaveearly") == 0) {
- list[idx] = NUM_LEAVEEARLY;
- } else if (strcmp(token, "present") == 0) {
- list[idx] = NUM_PRESENT;
- }
- idx++;
- token = strtok(NULL, " ");
- }
-
- int count;
- for (i = 0; i < idx; i++) {
- count = 0;
- for (j = i ;j < i + 7 && i + 7 <=idx; j++) {
- if (list[j] == NUM_ABSENT || list[j] == NUM_LATE || list[j] == NUM_LEAVEEARLY) {
- count++;
- }
- }
- if (count > 3) {
- printf("false\n");
- return;
- }
- }
- printf("true\n");
- }
-
- int main()
- {
- int n, i;
- char input[32] = {0};
-
- scanf("%d", &n);
- getchar();
-
- for (i = 0; i < n; i++) {
- memset(input, 0, sizeof(input));
- gets(input);
- // printf("%s\n", input);
- IsQuan(input);
- }
-
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。