Advertisement
Guest User

probE

a guest
Oct 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. bool isInt(string str)
  9. {
  10.     int len = str.length();
  11.     for(int i = 0; i < len; i++)
  12.         if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) return false;
  13.  
  14.     return true;
  15. }
  16.  
  17. bool cmp(string a, string b) {
  18.     string ax, bx;
  19.     ax = bx = "";
  20.     for(int i = 0; i < a.length(); i++)
  21.         ax += a[i];
  22.     for(int i = 0; i < b.length(); i++)
  23.         bx += b[i];
  24.  
  25.     return ax < bx;
  26. }
  27.  
  28. int main()
  29. {
  30.     string words[100];
  31.     int numbs[100];
  32.     string input;
  33.     bool isNum[100];
  34.     int cWord, cNums, cnt;
  35.  
  36.     cWord = cNums = cnt = 0;
  37.  
  38.     cin >> input;
  39.     while(input[0] != '.') {
  40.         char last = input[input.length() - 1];
  41.         input.erase(input.length() - 1, 1);
  42.  
  43.         if(isInt(input))
  44.         {
  45.             numbs[cNums] = stoi(input);
  46.             cNums++;
  47.             isNum[cnt] = true;
  48.         }
  49.         else{
  50.             words[cWord] = input;
  51.             cWord++;
  52.             isNum[cnt] = false;
  53.         }
  54.         cnt++;
  55.  
  56.         int ncount = 0;
  57.         int wcount = 0;
  58.  
  59.         if(last == '.')
  60.         {
  61.             string ans = "";
  62.             sort(numbs, numbs + cNums);
  63.             sort(words, words + cWord, cmp);
  64.             for(int i =0 ; i <cnt; i++) {
  65.                 if(isNum[i]) {
  66.                     ans += to_string(numbs[ncount]) + ", ";
  67.                     ncount++;
  68.                 }
  69.                 else{
  70.                     ans += words[wcount] + ", ";
  71.                     wcount++;
  72.                 }
  73.             }
  74.             if(isNum[cnt - 1]) {
  75.                 ans += to_string(numbs[ncount]) + ".";
  76.                 ncount++;
  77.             }
  78.             else{
  79.                 ans += words[wcount] + ".";
  80.                 wcount++;
  81.             }
  82.  
  83.             cout << ans << endl;
  84.             cin >> input;
  85.             cnt = cWord = cNums = 0;
  86.         }
  87.     }
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement