/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int toInt(string s) { int ret; istringstream os(s); os>>ret; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc, kk=1, n; string s; char ch; while(getline(cin, s)) { if(s==".") break; //cout<<s.size()<<endl; vector<int>v; vector<int>vi; vector<string>vs; map<string, string>original; for(int i=0; i<s.size(); i++) { //if(s[i]==' ') continue; string tmp=""; bool digitOnly = true; while(s[i]!=',' && s[i]!='.') { tmp+=s[i]; if(s[i]!='-' && !isdigit(s[i])) digitOnly=false; i++; } i++; if(digitOnly) { vi.push_back(toInt(tmp)); v.push_back(0); } else { string tmp2=""; for(int i=0;i<tmp.size();i++) tmp2+=tolower(tmp[i]); original[tmp2]=tmp; vs.push_back(tmp2); v.push_back(1); } } sort(vi.begin(), vi.end()); sort(vs.begin(), vs.end()); int i=0, j=0; if(v[0]==0) { cout<<vi[i]; i++; } else { cout<<original[vs[j]]; j++; } for(int k=1; k<v.size(); k++) { cout<<", "; if(v[k]==0) { cout<<vi[i]; i++; } else { cout<<original[vs[j]]; j++; } } cout<<".\n"; } return 0; }
Sunday, 20 September 2015
Scramble Sort (UVALive 2086, ZOJ 1225, POJ 1520, Regionals 2000 >> North America - Greater NY)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment