杭电OJ | 2629 【求助 待解决】身份证号 Wrong anwser

自己输出没问题,提交就是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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值