acm steps1.2.8(Identity Card)

来源:互联网 发布:龙与地下城 知乎 编辑:程序博客网 时间:2024/05/24 06:02

 

Problem Description
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.

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
1330000198910120036
 
Sample Output
He/She is from Zhejiang,and his/her birthday is on 10,12,1989 based on the table.

代码:

#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
   int n;
   string str,prov;
   cin>>n;
   getline(cin,str);///由于读入n之后没有处理换行,这个getline用于吸收换行符
   while(n>0)
   {
       n--;
       getline(cin,str);
       switch(str[0])
       {
       case '3':
        if(str[1]=='3')
            prov="Zhejiang";
        else
            prov="Shanghai";
        break;
       case '1':
        prov="Beijing";
        break;
       case '7':
        prov="Taiwan";
        break;
       case '8':
        if(str[1]=='1')
            prov="Hong Kong";
        else
            prov="Macao";
        break;
       case '5':
        prov="Tibet";
        break;
       case '2':
        prov="Liaoning";
        break;
       }
       cout<<"He/She is from "<<prov<<",and his/her birthday is on "<<str[10]<<str[11]<<','<<str[12]<<str[13]<<','<<str[6]<<str[7]<<str[8]<<str[9]<<" based on the table."<<endl;
   }
   return 0;
}

 

0 0