您的位置:首页 > 其它

HDOJ_ACM_steps——Identity Card

2013-03-30 15:46 281 查看
没什么难的,不过一个cout<<让我纠结了很久

学到一个新函数:



函数名: strncmp
功 能: 串比较
用 法: int strncmp(char *str1, char *str2, int maxlen);
说明:此函数功能即比较字符串str1和str2的前maxlen个字符。如果前maxlen字节完全相等,返回值就=0;在前maxlen字节比较过程中,如果出现str1
与str2
不等,则返回(str1
-str2
)。

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main() {
	int count;
	char s[20];
	string id[8] = {"33", "11", "71", "81", "82", "54", "21", "31"};
	string place[8]={"Zhejiang","Beijing","Taiwan","Hong Kong","Macao","Tibet","Liaoning","Shanghai"};
	scanf("%d",&count);
	while(count--){
		scanf("%s",&s);
		printf("He/She is from ");
		for(int i=0;i<8;i++){
			if(strncmp(s, id[i].c_str(), 2) ==0 ){
				cout<<place[i];//可能会有问题
			}
		}
		printf(",and his/her birthday is on ");
		printf("%c%c,%c%c,%c%c%c%c",s[10],s[11],s[12],s[13],s[6],s[7],s[8],s[9]);
		printf(" based on the table.");
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: