1009 说反话 (20 分)

mac2024-09-29  54

题目链接 答题思路是利用二维字符串数组对数据吸收,然后倒叙输出;

#pragma warning(disable:4996); #include <iostream> #include<stdio.h> #include<algorithm> #include<string.h> #include<stack> using namespace std; int main() { char word[100][80]; int x = 0; do { scanf("%s", word[x++]); } while (getchar() != '\n');//用do while是因为若用while会先判断吸收一个字母,导致答案错误,而用dowhile先做在判,能得到正确的值 for (int i = x - 1;i >= 0;i--) { if (i != 0) cout << word[i] << " "; else cout << word[i] << endl; } return 0; }
最新回复(0)