HDOJ_ACM_steps——Identity Card

 

没什么难的,不过一个cout<<让我纠结了很久

学到一个新函数:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值