PAT:1061. Dating (20) AC

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<algorithm>
using namespace std;

char alp[7][5]={"MON","TUE","WED","THU","FRI","SAT","SUN"};

int main()
{
  /*char test='E';
  printf("%d:",test-'A'+10);*/
  char s[4][70];
  int len[4];
  for(int i=0 ; i<4 ; ++i)
  {
    scanf("%s",s[i]);
    len[i]=strlen(s[i]);
  }
  int index=0,minlen=min(len[0],len[1]);
  for(index=0 ; index<minlen ; ++index)          //星期
  {
    if(s[0][index]==s[1][index] && s[0][index]>='A' && s[0][index]<='G')
    {
      printf("%s ",alp[s[0][index]-'A']);
      break;
    }
  }

  for(++index ; index<minlen ; ++index)          //时//【warning】必须先++index,不然还是指向D,下面出现错误
  {
    if(s[0][index]==s[1][index])
    {
      if(s[0][index]>='A' && s[0][index]<='N')
      {
        printf("%02d:",s[0][index]-'A'+10);      //【warning】看清格式!
        break;
      }
      else if(s[0][index]>='0' && s[0][index]<='9')
      {
        printf("%02d:",s[0][index]-'0');      //【warning】转为数字,才能02d输出
        break;
      }
    }
  }
  minlen=min(len[2],len[3]);
  for(int i=0 ; i<minlen ; ++i)              //分
  {
    if(s[2][i]==s[3][i] && isalpha(s[2][i]))
    {
      printf("%02d\n",i);
      break;
    }
  }
  return 0;
}
posted on 2015-03-10 11:48  Evence  阅读(174)  评论(0编辑  收藏  举报