Friday, 13 July 2018

uva problem 10286 Trouble with a Pentagon solution

  1. #include<bits/stdc++.h>
  2. #define x 1.0673956817111818692592637626711
  3. using namespace std;
  4. int main()
  5. {
  6.     double a;
  7.     while(scanf("%lf"&a)!=EOF){
  8.         printf("%0.10lf\n",a*x);
  9.     }
  10.  
  11.     return 0;
  12. }

uva problem 0260 Soundex solution

  1. #include<bits/stdc++.h>
  2. #include<string.h>
  3. using namespace std;
  4. int main()
  5. {
  6.     char str[25];
  7.     while(cin>>str){
  8.         int f=0,s=0,t=0,fr=0,fi=0,si=0;
  9.         for(int i=0;i<strlen(str);i++){
  10.             if((str[i]=='B' || str[i]=='F' || str[i]=='P' || str[i]=='V' )){
  11.                 if(str[i-1]!='B' && str[i-1]!='F' && str[i-1]!='P' && str[i-1]!='V')
  12.                 cout<<"1";
  13.  
  14.             }
  15.             if(str[i]=='C' || str[i]=='G' || str[i]=='J' || str[i]=='K' || str[i]=='Q' || str[i]=='S' || str[i]=='X' || str[i]=='Z' ){
  16.          if(str[i-1]!='C' && str[i-1]!='G' && str[i-1]!='J' && str[i-1]!='K' && str[i-1]!='Q' && str[i-1]!='S' && str[i-1]!='X' && str[i-1]!='Z' )
  17.               {
  18.                     cout<<"2";
  19.               }
  20.  
  21.             }
  22.             if (str[i]=='D' || str[i]=='T'){
  23.                     if (str[i-1]!='D' && str[i-1]!='T')
  24.                        cout<<"3";
  25.             }
  26.             if( str[i]=='L' ){
  27.                     if( str[i-1]!='L' )
  28.                     cout<<"4";
  29.             }
  30.             if(str[i]=='M' || str[i]=='N'){
  31.                     if(str[i-1]!='M' && str[i-1]!='N')
  32.                     cout<<"5";
  33.             }
  34.             if(str[i]=='R'){
  35.                     if(str[i-1]!='R')
  36.                     cout<<"6";
  37.             }
  38.         }
  39.         cout<<endl;
  40.     }
  41.     return 0;
  42. }

uva problem 10252 Common Permutation solution

  1. #include<bits/stdc++.h>
  2. #include<string.h>
  3. #include<ctype.h>
  4. #include<algorithm>
  5. #include<sstream>
  6. #include<string>
  7. using namespace std;
  8. int main()
  9. {
  10.     string str, st;
  11.     while(getline(cin,str)){
  12.             getline(cin, st);
  13.  
  14.       int strln= str.size();
  15.       int stln= st.size();
  16.       sort(str.begin(), str.end());
  17.       sort(st.begin(), st.end());
  18.  
  19.       if( str == st) {
  20.         cout<<str<<endl;
  21.         continue;
  22.       }
  23.       for(int i=0,j=0; i<strln && j<stln; ){
  24.         if(str[i] == st[j]) {
  25.             cout<<str[i];
  26.             i++;
  27.             j++;
  28.         }
  29.         else {
  30.             while(str[i]<st[j]){
  31.                 i++;
  32.                 if(i==strln)break;
  33.             }
  34.             while(st[j]<str[i]){
  35.                 j++;
  36.                 if(j==stln)break;
  37.             }
  38.         }
  39.       }
  40.       cout<<endl;
  41.     }
  42.     return 0;
  43. }

uva problem 10226 Hardwood Species solution

  1. #include<bits/stdc++.h>
  2. #include<algorithm>
  3. #include<string>
  4. #include<vector>
  5. #include <map>
  6. using namespace std;
  7. int main()
  8. {
  9.     int t;
  10.     scanf("%d"&t);
  11.     getchar();
  12.     getchar();
  13.     while(t--) {
  14.         map<string, int> record;
  15.         string tree;
  16.         int n = 0;
  17.         while(getline(cin, tree)) {
  18.             if(tree.compare("") == 0)
  19.                 break;
  20.             record[tree]++;
  21.             n++;
  22.         }
  23.         for(map<string, int>::iterator i = record.begin(); i != record.end(); i++)
  24.             cout << i->first << " " << fixed << setprecision(4) << i->second*100.0/<< endl;
  25.         if(t)
  26. puts("");
  27.  
  28.     }
  29.  
  30.     return 0;
  31.  
  32. }

variable declaration of c program

#include <stdbool.h> #include<bits/stdc++.h> #include <stdio.h> #include <string.h> #include <std...