Sunday, March 26, 2017

Uri 2508 - Fortune Teller

#include<bits/stdc++.h>
using namespace std;

int return_value(char ch){
   if(ch == 'A' or ch == 'J' or ch == 'S') return 1;
   else if(ch == 'B' or ch == 'K' or ch == 'T') return 2;
   else if(ch == 'C' or ch == 'L' or ch == 'U') return 3;
   else if(ch == 'D' or ch == 'M' or ch == 'V') return 4;
   else if(ch == 'E' or ch == 'N' or ch == 'W') return 5;
   else if(ch == 'F' or ch == 'O' or ch == 'X') return 6;
   else if(ch == 'G' or ch == 'P' or ch == 'Y') return 7;
   else if(ch == 'H' or ch == 'Q' or ch == 'Z') return 8;
   else if(ch == 'I' or ch == 'R') return 9;
}
int single_digit(int n){
   int t = 0;
    while(n != 0){
        t += n % 10;
        n /= 10;
        }
   return t;
}
int main()
{
   // freopen("in.txt","r",stdin);
    string s;
    while(getline(cin,s)){
        transform(s.begin(), s.end(),s.begin(), ::toupper);
        int sum = 0;
        for(int i = 0 ;i < s.size() ; i++ ) {
            if(s[i] != 32)
            sum += return_value(s[i]);
        }
        while(sum > 9){
            sum = single_digit(sum);
        }
         cout << sum << endl;
    }

    return 0;
}

Uri 2496 - The Only Chance

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    int n,t,l;
    string s;
    string orginal_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cin >> n;
    while(n--){
        bool b = true;
        int p = 0;
        cin >> t;
        cin >> s;
        for(int i = 0; i < t; i++){
            if(s[i] != orginal_string[i]){
               if(orginal_string[i] != s[((int)(s[i]) - 65)] or p > 0){
                     b = false;
                     break;
               }else{
                   swap(s[i],s[((int)(s[i]) - 65)]);
                   p++;
               }
            }
        }
     cout << ((b == true and p < 2) ?  "There are the chance.\n" : "There aren't the chance.\n");
    }
    return 0;
}

Uri 2495 - Where is my Pen?

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    int n,k,l,res = 0;
     while(cin >> n){
        int ans[100010];
        memset(ans,0,sizeof ans);
        l = n;
        n--;
        while(n--){
            cin >> k;
            ans[k] = 1;
        }
        for(int i = 1 ; i <= l ;i++){
            if(ans[i] == 0) {
                res = i ;
                break;
            }
        }
        cout << res << endl;
     }
    return 0;
}

Uri 2290 - Apaixornados Numbers

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    long long ar[100010];
    int n;
    while(cin  >> n and n != 0){
        memset(ar,0,sizeof ar);
            int t = 0;
        for(int i = 0;i < n ; i++) cin >> ar[i];

        sort(ar,ar+n);
        for(int i= 0 ; i < n and t < 2 ;){
             if(ar[i] == ar[i+1] and i < n-1){
                i += 2;
             }else{
                 cout << ar[i];
                 cout << ((t == 1) ?  "\n" : " ") ;
                 i++;
                 t++;
             }
        }
    }
    return 0;
}

Uri 1861 - Hall of Murderers

#include <bits/stdc++.h>

using namespace std;

 int main()
 {
     int t = 0;
     string name1, name2;
     multimap < string , int> criminal,vectim;
     map < string ,int > ans;
     while(cin >> name1 >> name2){
         criminal.insert(pair(name1,0));
         vectim.insert(pair(name2,0));
     }
     for(multimap < string , int > :: iterator it = criminal.begin(); it != criminal.end(); it++){
         string as = it->first;
         int t = 1;
        if(vectim.count(as) == 0){
            ans[as]++;
        }
     }

     cout << "HALL OF MURDERERS" << endl;
         for(map < string , int > ::iterator it2 = ans.begin(); it2 != ans.end();it2++){
         cout << it2->first << " " << it2->second << endl;
     }
     return 0;
 }

Uri 2510 - Batmain

#include <bits/stdc++.h>  


 using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  while(n--) {
      cin >> s;
      cout << ((s != "Batman") ?  "Y" : "N") << endl;
  }

    return 0;
}