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
)。
”
学到一个新函数:
“
函数名: 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; }
相关文章推荐
- HDOJ_ACM_steps——IBM Minus One
- HDOJ_ACM_steps——第二小整数
- HDOJ_ACM_steps——Buildings
- hdoj acm steps 1.2.4(GPA)
- HDOJ_ACM_steps—— Higher Math
- HDOJ_ACM_steps——Vowel Counting
- HDOJ--ACM-Steps--2.1.3--Cake(GCD,简单数学)
- hdu acm steps Biker's Trip Odometer
- [小结]HDU ACM Steps
- HDOJ1078 FatMouse and Cheese【动态规划】-----武科大ACM暑期集训队选拔赛2题
- ACM--勾股定理--HDOJ 2393--Higher Math
- hdoj&nbsp;&nbsp;acm&nbsp;&nbsp;&nbsp;1592
- ACM--公式--HDOJ 1012--u Calculate e--水
- ACM--steps--2.2.8--第一类stirling数
- ACM--类Fibonacci 数列--HDOJ 1021--Fibonacci Again--水
- ACM--steps--3.1.7--不容易系列之(3)—— LELE的RPG难题
- ACM--steps--4.1.3--Pie(二分)
- ACM--steps--4.2.1--Rescue(BFS+priority)
- HDOJ HDU 2069 Coin Change ACM 2069 IN HDU ..WA 真的成为习惯了...................
- ACM-steps--4.2.6--Find a way