输入方式:先输入一个整型,再输入不带空格的字符串。
思考:先输入不带空格的字符串,用scanf_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]; for (int i = 0; i<19; i++) scanf("%c", &a[i]); 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.\n"); } }
时间: 2024-10-03 22:47:42