wrench786

Soundex Indexing UVA - 739

Jan 30th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define wrench786 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  3. #define ll long long
  4. #define PI (acos(-1.0))
  5. #define LIMIT 1000000000
  6. #define pb push_back
  7. using namespace std;
  8.  
  9. void start(){
  10.     int i;
  11.     for(i=0;;i++){
  12.         if(i==9){
  13.             cout<<"NAME";
  14.             i+=3;
  15.         }
  16.         else if(i==34){
  17.             cout<<"SOUNDEX CODE"<<endl;
  18.             break;
  19.         }
  20.         else cout<<" ";
  21.     }
  22. }
  23.  
  24. void finish(){
  25.     int i,j;
  26.     for(j=0;j<5;j++){
  27.         for(i=0;;i++){
  28.             if(i==9){
  29.                 if(j==4){
  30.                     cout<<"|__ Column 10"<<endl;
  31.                     break;
  32.                 }
  33.                 else if(j) cout<<'|';
  34.                 else cout<<" ";
  35.             }
  36.             else if(i==19){
  37.                 if(!j){
  38.                     cout<<"END OF OUTPUT"<<endl;
  39.                     break;
  40.                 }
  41.                 else if(j==3){
  42.                     cout<<"|__ Column 20"<<endl;
  43.                     break;
  44.                 }
  45.                 else if(j) cout<<'|';
  46.                 else cout<<" ";
  47.             }
  48.             else if(i==34){
  49.                 if(j==2){
  50.                     cout<<"|__ Column 35"<<endl;
  51.                     break;
  52.                 }
  53.                 else if(j) {
  54.                     cout<<'|'<<endl;
  55.                     break;
  56.                 }
  57.                 else cout<<" ";
  58.             }
  59.             else cout<<" ";
  60.         }
  61.     }
  62. }
  63. char check(char x){
  64.     if(x=='B' ||  x=='P' || x=='F' || x=='V' ) return '1';
  65.     else if(x=='C' ||  x=='S' || x=='K' || x=='G' || x=='J' ||  x=='Q' || x=='X' || x=='Z') return '2';
  66.     else if( x=='D' ||  x=='T') return '3';
  67.     else if(x=='L' ) return '4';
  68.     else if(x=='M' ||  x=='N') return '5';
  69.     else if(x=='R') return '6';
  70.     else return '0';
  71. }
  72. int main(){
  73.     wrench786
  74.  
  75. #ifndef ONLINE_JUDGE
  76.     clock_t tStart = clock();
  77.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  78. #endif
  79.  
  80.     start();
  81.     string inp;
  82.     int i;
  83.     char ch;
  84.     while(cin>>inp){
  85.         string outp;
  86.         for(i=0;i<inp.size();i++){
  87.             ch = check(inp[i]);
  88.             if(!i) outp.pb(inp[i]);
  89.             else if(ch!='0'){
  90.                 if(outp.size()==1){
  91.                     if(check(outp[0])!=ch){
  92.                         outp.pb(ch);
  93.                     }
  94.                 }
  95.                 else if(outp[outp.size()-1]!=ch){
  96.                     outp.pb(check(inp[i]));
  97.                 }
  98.             }
  99.            
  100.         }
  101.         if(outp.size()<4){
  102.             while(outp.size()<4){
  103.                 outp.pb('0');
  104.             }
  105.         }
  106.         else if(outp.size()>4){
  107.             outp.erase(outp.begin()+4,outp.end());
  108.         }
  109.         for(int i=0;;i++){
  110.             if(i==9){
  111.                 cout<<inp;
  112.                 i+=inp.size()-1;
  113.             }
  114.             else if(i==34){
  115.                 cout<<outp<<endl;
  116.                 break;
  117.             }
  118.             else cout<<" ";
  119.         }
  120.     }
  121.     finish();
  122.  
  123. #ifndef ONLINE_JUDGE
  124.     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  125. #endif
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment