读书人

ACM:1.2.8 Identity Card C语言版的答

发布时间: 2013-09-24 10:59:52 作者: rapoo

ACM:1.2.8 Identity Card C语言版的解题方案
#include"stdio.h"#include"string.h"char *substr(const char *str,int n,int m,char p[]){char *cour;int i,j=0;cour=str;if(m>=n&&n>=0){for(i=0;i<m;i++){if(i>=n){p[j]=*cour;j++;}cour++;}p[j]='\0';cour=p;return cour;}else{return 0;}}int main(){char identity[20];char pr[5],mon[5],day[5],year[7];char *loc;int i;scanf("%d",&i);while(i--){scanf("%s",identity);substr(identity,0,2,pr);substr(identity,10,12,mon);substr(identity,12,14,day);substr(identity,6,10,year);switch(atoi(pr)){case 33:loc="Zhejiang";break;case 11:loc="Beijing";break;case 71:loc="Taiwan";break;case 81:loc="Hong Kong";break;case 82:loc="Macao";break;case 54:loc="Tibet";break;case 21:loc="Liaoning";break;case 31:loc="Shanghai";break;default:break;}printf("He/She is from %s,and his/her birthday is on %s,%s,%s based on the table.\n",loc,mon,day,year);}}

?

读书人网 >C语言

热点推荐