提交时间:2023-12-25 13:45:31

运行 ID: 35032

#include<bits/stdc++.h> using namespace std; string word[110], s; int main() { int cnt = 0; while(cin >> s) {//连续读入,遇到空格就停止 cnt++;//从下标1开始用 ,表示第几个字符串 word[cnt] = s;//存到字符串数组中 } for (int i = 1; i < cnt; i++) {//冒泡排序 for (int j = 1; j < cnt; j++) { if(word[j] > word[j + 1]) { swap(word[j], word[j + 1]); } } } for (int i = 1; i <= cnt; i++) {//输出,若有多个,只输出一次 if(word[i] == word[i + 1]) {//出现多个,输出最后一个 continue;//执行下一次循环,后面的语句不执行 } cout << word[i] << endl; /* 另一种方式 if(word[i] == word[i + 1]) { ; }else { cout<<word[i] << endl; } */ } return 0; }