2018年3月15日 星期四

[C_ST126-易] 字元排序(C++)

[C_ST126-易] 字元排序

Time Limit: 2 seconds
問題描述 :
連續輸入兩個英文字元並依據其在字母表的位置重新排序
輸入說明 :
第一行先輸入一個整數(1 ≦ ≦ 10)表示有幾筆測資,接下來有n筆測資,每筆測資為二個英文字元
輸出說明 :
輸出二個英文字元排序後的結果

範例 :

輸入範例輸出範例
2
ka
RQ
a
k
Q
R

  1. #include <iostream>  
  2. #include <stdio.h>  
  3. #include <ctype.h>  
  4. #include <string>  
  5. using namespace std;  
  6.   
  7. int main() {  
  8.     // [C_ST126-易] 字元排序  
  9.     string N;  
  10.     getline(cin, N);  
  11.     int n = stoi(N);  
  12.     string s;  
  13.     for(int i = 0;i < n;i++)  
  14.     {  
  15.         getline(cin, s);  
  16.         if((int)tolower(s[0]) > (int)tolower(s[1]))  
  17.         //if((int)s[0] > (int)s[1])  
  18.         {  
  19.             cout << s[1] << endl;  
  20.             cout << s[0] << endl;  
  21.         }  
  22.         else  
  23.         {  
  24.             cout << s[0] << endl;  
  25.             cout << s[1] << endl;  
  26.         }  
  27.     }  
  28.     return 0;  
  29. }  

沒有留言:

張貼留言