OpenJudgeP1.10.10:单词排序 __(刷题)_水题

这道题研究了好久,网上也查了很多算法,

终于发现一个很牛的函数

compare()  

还是很强很强的。

这道题的读入比较难写,但是只要写完这个,基本就没什么难题了!!!

题目戳这里

//compare():compare 是逐字符比较的 从第一位开始 若相同则比较下一字符 若不同 就马上出结果了

                      如"dog”与"cat dog cat"相比的话,第一字符d大于c则 "dog”大于"cat dog cat。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     string words[100];
 6     int num=0;
 7     while (cin>>words[num])
 8     {
 9         bool is=false;
10         for (int i=0;i<num;i++)
11         {
12             if (words[i].compare(words[num]) == 0)
13             {
14                 is = true;
15                 break;
16             }
17         }
18         if(!is) num++;
19     }
20     sort(words,words+num);
21     for (int i=0; i<num; i++) cout << words[i] << endl;
22     return 0;
23 }

字符串&排序刷完了!!!接下来会是一些枚举,模拟......算法为主的题目!!!加油吧!!!

原文地址:https://www.cnblogs.com/pengcheng-official/p/9459925.html