输入方式:先输入一个整型,再输入不带空格未知长度/已知长度的字符串。
思考:用scanf_s()函数输入整型,再循环输入不带空格未知长度的字符串,用gets_s()函数。
注意:scanf_s()函数要多加一个%c.&d,来避免对gets_s函数输入字符串的影响。
#include<stdio.h> #include<iostream> #include<string.h> using namespace std; int main() { int n; char d; scanf("%d%c", &n, &d); while (n--) { char a[19]; gets_s(a); printf("He/She is from "); if (a[0] == '3'&&a[1] == '3') printf("Zhejiang,"); else if (a[0] == '1'&&a[1] == '1') printf("Beijing,"); else if (a[0] == '7'&&a[1] == '1') printf("Taiwan,"); else if (a[0] == '8'&&a[1] == '1') printf("Hong Kong,"); else if (a[0] == '8'&&a[1] == '2') printf("Macao,"); else if (a[0] == '5'&&a[1] == '4') printf("Tibet,"); else if (a[0] == '2'&&a[1] == '1') printf("Liaoning,"); else if (a[0] == '3'&&a[1] == '1') printf("Shanghai,"); printf("and his/her birthday is on "); printf("%c%c,%c%c,%c%c%c%c", a[10], a[11], a[12], a[13], a[6], a[7], a[8], a[9]); printf(" based on the table. "); } }