/*
hdu2629 题意 输入一个18位的身份证号码 前六位是地区 再八位是出生年月日 后四位特殊标号
前六位地区 在题目中有八个地区 ,输出
He/She is from “地区”,and his/her birthday is on 月,日,年 based on the table.
if语句就好 问题就是输入 我用了scanf的控制输入语句 但是WA料想是输入字符串 而我用的是整形数组,菜不成声
*/
#include <stdio.h> //AC代码 别人的 #include <string.h>//hdu 2629 int main() { int n;char a[19];scanf("%d",&n); while(n--) { int year,mon,day;char s[10]; scanf("%s",a); printf("He/She is from "); if (a[0]==‘3‘ && a[1]==‘3‘){ printf("Zhejiang");}//字符比较 else if(a[0]==‘1‘ && a[1]==‘1‘){ printf("Beijing");} else if(a[0]==‘7‘ && a[1]==‘1‘){ printf("Taiwan");} else if(a[0]==‘8‘ && a[1]==‘1‘){ printf("Hong Kong");} else if(a[0]==‘8‘ && a[1]==‘2‘){ printf("Macao");} else if(a[0]==‘5‘ && a[1]==‘4‘){ printf("Tibet");} else if(a[0]==‘2‘ && a[1]==‘1‘){ printf("Liaoning");} else if(a[0]==‘3‘ && a[1]==‘1‘){ printf("Shanghai");} printf(",and his/her birthday is on "); printf("%c%c,%c%c,%c%c%c%c",a[10],a[11],a[12],a[13],a[6],a[7],a[8],a[9]); printf(" based on the table.\n"); } return 0; }
#include <stdio.h>//我写的 CE #include <string.h>//hdu 2629 int main() { int n;int s[10];scanf("%d",&n); while(n--) { int s[10],year,mon,day;char s[20]; scanf("%1d%1d%1d%1d%1d%1d%4d%2d%2d%*d",&s[1],&s[2],&s[3],&s[4],&a[5],&a[6],&year,&mon,&day); printf("He/She is from "); if(s[1] == 3 && s[2] == 3) printf("Zhejiang"); else if(s[1] == 1 && s[2] == 1) printf("Beijing"); else if(s[1] == 7 && s[2] == 1) printf("Taiwan"); else if(s[1] == 8 && s[2] == 1) printf("Hong Kong"); else if(s[1] == 8 && s[2] == 2) printf("Macao"); else if(s[1] == 2 && s[2] == 1) printf("Liaoning"); else if(s[1] == 5 && s[2] == 4) printf("Tibet"); else if(s[1] == 3 && s[2] == 1) printf("Shanghai"); printf(",and his/her birthday is on "); printf("%d,%d,%d based on the table.\n",mon,day,year); } return 0; }
#include <stdio.h> #include <string.h> int main() { int n; int s[20],i,len; char str[20]; scanf("%d%*c",&n); while(n--) { gets(str); len = strlen(str); for(i = 0;i<len;i++) { s[i+1] = str[i]-48; //将字符重新构建一个数组 } printf("He/She is from "); if(s[1] == 3 && s[2] == 3) printf("Zhejiang"); else if(s[1] == 1 && s[2] == 1) printf("Beijing"); else if(s[1] == 7 && s[2] == 1) printf("Taiwan"); else if(s[1] == 8 && s[2] == 1) printf("Hong Kong"); else if(s[1] == 8 && s[2] == 2) printf("Macao"); else if(s[1] == 2 && s[2] == 1) printf("Liaoning"); else if(s[1] == 5 && s[2] == 4) printf("Tibet"); else if(s[1] == 3 && s[2] == 1) printf("Shanghai"); printf(",and his/her birthday is on %d%d,%d%d,%d%d%d%d based on the table.\n",s[11],s[12],s[13],s[14],s[7],s[8],s[9],s[10]); } }