Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <sstream>
- #include <cstdlib>
- #include "ctype.h"
- using namespace std;
- char join(char a, char b);
- char join(int a, int b);
- int main() {
- std::vector<char>letr;
- std::vector<int> numb;
- std::stringstream ss;
- std::string s;
- bool l =0;
- char a, b, forrige;
- int cnt=0;
- int tip;
- while (getline(cin,s)){
- std::stringstream ss(s);
- while(ss >> a)
- {
- if (isalpha(a)==1024)
- {
- letr.push_back(a);
- b=a;
- }
- if (isdigit(a)==1 && forrige == ',' || isdigit(a)==1 && forrige==':')
- {
- numb.push_back(a);
- letr.push_back(b);
- }
- if(isdigit(forrige)==1 && isalpha(a)==0 && a != ',' && a!= ':'){
- numb.pop_back();
- numb.push_back(join(forrige,a));
- }
- forrige = a;
- }
- letr.pop_back();
- }
- for (int k=0;k<numb.size();k++){
- numb[k]= numb[k]-48;
- }
- int len = numb.size(), maxi, i, tmp, tmp2;
- while(len>0)
- {
- maxi=0;
- for(i = 1; i<len; i++)
- {
- if (numb[i] > numb[maxi])
- {
- maxi = i;
- }
- }
- tmp2= letr[len-1];
- tmp = numb[len -1];
- letr[len-1]=letr[maxi];
- numb[len-1]=numb[maxi];
- letr[maxi]= tmp2;
- numb[maxi] = tmp;
- len--;
- }
- for(std::vector<char>::iterator l=letr.begin(); l!=letr.end(); l++)
- {
- cout << *l;
- }
- cout << endl;
- return 0;
- }
- char join(int a, int b){
- return (a*10 +b);
- }
- char join(char a, char b)
- {
- a=a-48;
- b=b-48;
- return (a*10 +b + 48);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement