PAT乙级1014题解

恶心!太恶心啦!debug用了一个多小时T^T不过很大程度上是我憨憨...一定要记得最后小时和分钟前面都要有补0操作!注意表示星期(第一个)的一定要是A-G之间的字母!这个有用例卡的,我被这个用例卡了一个小时qwqAC代码如下,确实是一道字符串的基础操作练习题,感受到了PAT用例的全面(哭)!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int min(int a, int b){
    return (a < b)? a : b;
}
int main()
{
    char sts[5][61];
    for(int i = 0; i < 4; i++){
        gets(sts[i]);
    }
    char scrt[3];
    int ctscrt = 0;

    int loc = 0;
    for(int i = 0; i < min(strlen(sts[1]), strlen(sts[0])); i++){
        if(sts[0][i] == sts[1][i]){
            if(ctscrt == 0){
                if(sts[0][i] >= 'A' && sts[0][i] <= 'G'){
                    scrt[ctscrt++] = sts[0][i];
                }
            }else if(ctscrt == 1){
                if((sts[0][i] >= 'A' && sts[0][i] <= 'N') || isdigit(sts[0][i])){
                    scrt[ctscrt++] = sts[0][i];
                }
            }else if(ctscrt == 2){
                if(isalpha(sts[0][i])){
                    scrt[ctscrt++] = sts[0][i];
                    loc = i;
                    break;
                }
            }
        }
    }



    for(int i = 0; i < min(strlen(sts[2]), strlen(sts[3])); i++){
        if(sts[2][i] == sts[3][i]){
            if(ctscrt == 0){
                if(sts[2][i] >= 'A' && sts[2][i] <= 'G'){
                    scrt[ctscrt++] = sts[2][i];
                }
            }else if(ctscrt == 1){
                if((sts[2][i] >= 'A' && sts[2][i] <= 'N') || isdigit(sts[2][i])){
                    scrt[ctscrt++] = sts[2][i];
                }
            }else if(ctscrt == 2){
                if(isalpha(sts[2][i])){
                    scrt[ctscrt++] = sts[2][i];
                    loc = i;
                    break;
                }
            }
        }
    }
    char Week[8][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    printf("%s ", Week[scrt[0] - 'A']);
    int hour;
    if(isdigit(scrt[1])){
        hour = atoi(&scrt[1]);
    }else{
        hour = scrt[1] - 'A' + 10;
    }
    printf("%02d:%02d", hour, loc);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值