Tranvick

Untitled

Jan 9th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #define forn(I,B) for (int I=1;I<=(B);I++)
  5. #define rep(I,B) for (int I=0;I<(B);I++)
  6.  
  7. using namespace std;
  8.  
  9. string vals[555],buf,s;
  10. int ptr,n;
  11.  
  12. bool cmp(string a,string b){
  13.     int x=a.length(),y=b.length();
  14.     if (x!=y) return x<y;
  15.     rep(i,x) if (a[i]!=b[i]) return a[i]<b[i];
  16.     return 0;
  17. }
  18.  
  19. int main(){
  20.     cin>>n;
  21.     forn(i,n){
  22.         cin>>s;
  23.         int l=s.length();
  24.         rep(j,l)
  25.             if (s[j]>='0' && s[j]<='9'){
  26.                 buf="";
  27.                 while (j<l && s[j]>='0' && s[j]<='9') buf+=s[j++];
  28.                 while (buf[0]=='0' && buf.length()>1) buf.erase(0,1);
  29.                 vals[++ptr]=buf;
  30.             }
  31.     }
  32.     sort(vals+1,vals+ptr+1,cmp);
  33.     forn(i,ptr) cout<<vals[i]<<endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment