我是靠谱客的博主 清秀泥猴桃,最近开发中收集的这篇文章主要介绍H - Identity CardH - Identity Card,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

H - Identity Card

Do you own an ID card?You must have a identity card number in your family’s Household Register. From the ID card you can get specific personal information of everyone. The number has 18 bits,the first 17 bits contain special specially meanings:the first 6 bits represent the region you come from,then comes the next 8 bits which stand for your birthday.What do other 4 bits represent?You can Baidu or Google it.

Here is the codes which represent the region you are in.

Zheijing 330000 Beijing 110000 Taiwan 710000 Hong Kong 810000
Maocao 820000 Tibet 540000 Liaoning 210000 Shanghai 310000

However,in your card,maybe only 33 appears,0000 is replaced by other numbers.
Here is Samuel’s ID number 331004198910120036 can you tell where he is from?The first 2 numbers tell that he is from Zhengjiang Province,number 19891012 is his birthday date (yy/mm/dd).

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.
起初,做这道题目出现的错误是在字符串赋值那里,我直接写成了c=”Zhejiang”;这样就出现了错误,下面说一下字符串赋值;
char *a=”Zhejiang”,
也可以 char*a;a=”Zhejiang”;(用字符指针指向一个字符串)
还可以 char a[]=”Zhejiang”;(用字符数组存放一个字符串)
char a[20]=”Zhejaing”;这样是正确的
char a[20];a=”Zhejaing”,这样赋值是错误的
这种情况容易出现,a虽然是指针,但是它已经指向在堆栈中分配的20个字符空间,现在这个情况a又指向数据区中的hello常量,这里的指针a出现混乱,不允许!
注:不能先定义再赋值;
还可以利用函数 strcpy来给字符串赋值
char a[20];
strcpy(a,”Zhejaing”);
比较两字符串 要用strcmp()函数

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
int main()
{
int n,i,j,k,l;
int len;
char a[20];
char b[20];
char c[20];
char d[20];
char e[20];
char f[20];
scanf("%d",&n);
while(n--)
{
scanf("%s",a);
len=strlen(a);
j=0;
k=0;
l=0;
for(i=0;i<2;i++)
{
b[i]=a[i];
}
b[i]='';
if(strcmp(b,"33")==0)
{
strcpy(c,"Zhejiang");
}
else if(strcmp(b,"82")==0)
{
strcpy(c,"Macao");
}
else if(strcmp(b,"11")==0)
{
strcpy(c,"Beijing");
}
else if(strcmp(b,"54")==0)
{
strcpy(c,"Tibet");
}
else if(strcmp(b,"71")==0)
{
strcpy(c,"Taiwan");
}
else if(strcmp(b,"21")==0)
{
strcpy(c,"Liaoning");
}
else if(strcmp(b,"81")==0)
{
strcpy(c,"Hong Kong");
}
else if(strcmp(b,"31")==0)
{
strcpy(c,"Shanghai");
}
for(i=6;i<10;i++)
{
d[j++]=a[i];
}
d[j]='';
for(i=10;i<12;i++)
{
e[k++]=a[i];
}
e[k]='';
for(i=12;i<14;i++)
{
f[l++]=a[i];
}
f[l]='';
printf("He/She is from %s,and his/her birthday is on %s,%s,%s based on the table.n",c,e,f,d);
}
return 0;
}

最后

以上就是清秀泥猴桃为你收集整理的H - Identity CardH - Identity Card的全部内容,希望文章能够帮你解决H - Identity CardH - Identity Card所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部