Advertisement
Palatis

string sort compare

Mar 1st, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. /* http://tw.knowledge.yahoo.com/question/question?qid=1512030105710 */
  2.  
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <string>
  6.  
  7. int main()
  8. {
  9.     /* 需要兩個字串 */
  10.     std::string s1, s2;
  11.  
  12.     while (1)
  13.     {
  14.         /*
  15.          * !(std::cin >> s1) 判斷輸入是否失敗
  16.          * s1 == "STOP!!" 判斷輸入是不是 "STOP!!"
  17.          * 以上兩個成立任一個,跳出 while 迴圈
  18.          */
  19.         if (!(std::cin >> s1) || s1 == "STOP!!")
  20.             break;
  21.  
  22.         if (!(std::cin >> s2) || s2 == "STOP!!")
  23.             break;
  24.  
  25.         /* 排序 */
  26.         std::sort(s1.begin(), s1.end());
  27.         std::sort(s2.begin(), s2.end());
  28.  
  29.         /* 比較,相等印 "yes"、不相等印 "no" */
  30.         std::cout << (s1 == s2 ? "yes" : "no") << std::endl;
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement