概述
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 310000However,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]='