提交时间:2024-05-17 15:31:51

运行 ID: 47375

#include<iostream> #include<algorithm>//swap() #include<string> using namespace std; int main() { string word[110], s; int cnt = 1; while(cin >> s) {//连续读入 ,停止符号ctrl+z word[cnt] = s; cnt++; } cnt = cnt - 1;//cnt-1个单词 for (int t = 1; t < cnt; t++) {//冒泡排序 for (int wei = 1; wei < cnt - (t - 1); wei++) { if(word[wei] > word[wei + 1]) { swap(word[wei], word[wei + 1]); } } } for (int i = 1; i <= cnt; i++) {//去重输出 if(word[i] == word[i + 1]) { continue; } cout << word[i] << endl;; } return 0; }