Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <string>
- #include <algorithm>
- using namespace std;
- bool isInt(string str)
- {
- int len = str.length();
- for(int i = 0; i < len; i++)
- if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) return false;
- return true;
- }
- bool cmp(string a, string b) {
- string ax, bx;
- ax = bx = "";
- for(int i = 0; i < a.length(); i++)
- ax += a[i];
- for(int i = 0; i < b.length(); i++)
- bx += b[i];
- return ax < bx;
- }
- int main()
- {
- string words[100];
- int numbs[100];
- string input;
- bool isNum[100];
- int cWord, cNums, cnt;
- cWord = cNums = cnt = 0;
- cin >> input;
- while(input[0] != '.') {
- char last = input[input.length() - 1];
- input.erase(input.length() - 1, 1);
- if(isInt(input))
- {
- numbs[cNums] = stoi(input);
- cNums++;
- isNum[cnt] = true;
- }
- else{
- words[cWord] = input;
- cWord++;
- isNum[cnt] = false;
- }
- cnt++;
- int ncount = 0;
- int wcount = 0;
- if(last == '.')
- {
- string ans = "";
- sort(numbs, numbs + cNums);
- sort(words, words + cWord, cmp);
- for(int i =0 ; i <cnt; i++) {
- if(isNum[i]) {
- ans += to_string(numbs[ncount]) + ", ";
- ncount++;
- }
- else{
- ans += words[wcount] + ", ";
- wcount++;
- }
- }
- if(isNum[cnt - 1]) {
- ans += to_string(numbs[ncount]) + ".";
- ncount++;
- }
- else{
- ans += words[wcount] + ".";
- wcount++;
- }
- cout << ans << endl;
- cin >> input;
- cnt = cWord = cNums = 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement