PAT:1014. 福尔摩斯的约会 (20) AC

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<algorithm>
using namespace std;
char g1[99],g2[99],g3[99],g4[99];
char alp[7][5]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main()
{
  scanf("%s",g1);
  scanf("%s",g2);
  scanf("%s",g3);
  scanf("%s",g4);
  int len1=strlen(g1);
  int len2=strlen(g2);
  int len3=strlen(g3);
  int len4=strlen(g4);
  int MINlen=min(len1,len2);
  int i;
  for(i=0 ; i<MINlen ; ++i)            //找星期
  {
    if(g1[i]==g2[i] && g1[i]>='A' && g1[i]<='G')
    {
      printf("%s ",alp[g1[i]-'A']);        //【skill】-'A'变成从0开始数的数字
      break;
    }
  }
  for(++i ; i<MINlen ; ++i)              //找小时
  {
    if(g1[i]==g2[i])
    {
      if(g1[i]>='A' && g1[i]<='N')
    {
        printf("%02d:",g1[i]-'A'+10);        //【caution】-‘A’之后从0开始,而A代表的是10,勿忘+10
    break;
    }
      else if(g1[i]>='0' && g1[i]<='9')
    {
        printf("%02d:",g1[i]-'0');
    break;
    }
    }
  }
  MINlen=min(len3,len4);
  for(int i=0 ; i<MINlen ; ++i)            //找分钟
  {
    if(g3[i]==g4[i] && isalpha(g3[i]))        //相同,判断是否为字母
    {
      printf("%02d",i);
      break;
    }
  }
  //system("pause");
  return 0;
}
posted on 2015-03-07 17:20  Evence  阅读(177)  评论(0编辑  收藏  举报