H

来源:互联网 发布:skycc软件 编辑:程序博客网 时间:2024/06/10 03:14

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]='\0';        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]='\0';        for(i=10;i<12;i++)        {            e[k++]=a[i];        }        e[k]='\0';        for(i=12;i<14;i++)        {            f[l++]=a[i];        }        f[l]='\0';        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;}
原创粉丝点击