Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
39999 | hu | 单词排序 | C++ | Accepted | 1 MS | 256 KB | 602 | 2024-02-06 20:03:21 |
#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; }