自己输出没问题,提交就是Wrong anwser,有看到的前辈帮忙解决下~
笔记:
1. C语言中字符串不可以直接复制
char a[4];
a = "abc"; //错误写法
strcpy(a,"abc"); //正确写法要用strcpy函数
2. C语言中字符串不可以用关系运算符进行比较
if(a=="abc") //错误写法
if(strcmp(a,"abc")==0) //正确写法用strcmp函数
strcmp函数:
- 如果返回值 < 0,则表示 str1 小于 str2。
- 如果返回值 > 0,则表示 str2 小于 str1。
- 如果返回值 = 0,则表示 str1 等于 str2。
Input Input will contain 2 parts:
A number n in the first line,n here means there is n test cases. For each of the test cases,there is a string of the ID card number.
Output Based on the table output where he is from and when is his birthday. The format you can refer to the Sample Output.
Sample Input
1
330000198910120036
Sample Output
He/She is from Zhejiang,and his/her birthday is on 10,12,1989 based on the table.
#include <stdio.h>
#include <string.h>
int main(){
int inputnum;
scanf("%d",&inputnum);
getchar();
for(;inputnum!=0;inputnum--){
char id[18];
char region[2];
char regionname[20];
char year[4];
char month[2];
char day[2];
gets(id);
strncpy(region,id,2);
strncpy(year,id+6,4);
strncpy(month,id+10,2);
strncpy(day,id+12,2);
if(strcmp(region, "33") == 0){
strcpy(regionname,"Zhejiang");
}
else if(strcmp(region, "11") == 0){
strcpy(regionname,"Beijing");
}
else if(strcmp(region, "71") == 0){
strcpy(regionname,"Taiwan");
}
else if(strcmp(region, "81") == 0){
strcpy(regionname,"Hong Kong");
}
else if(strcmp(region, "82") == 0){
strcpy(regionname,"Macao");
}
else if(strcmp(region, "54") == 0){
strcpy(regionname,"Tibet");
}
else if(strcmp(region, "21") == 0){
strcpy(regionname,"Liaoning");
}
else if(strcmp(region, "31") == 0){
strcpy(regionname,"Shanghai");
}
printf("He/She is from %s,and his/her birthday is on %s,%s,%s based on the table.\n",regionname,month,day,year);
}
return 0;
}