Saturday, April 1, 2017

Uri 2520 - The Last Analógimôn

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

int main()
{
    int n,m,a,b,c,r;
    while(scanf("%d %d",&n,&m) != EOF){
       int ans[101][101];
     for(int i = 0;  i < n ;i++){
       for(int j = 0; j < m ;j++){
        scanf("%d",&ans[i][j]);
        if(ans[i][j] == 1) a = i,b = j;
        if(ans[i][j] == 2) r = i, c = j;
       }
     }
       int res = 0;
       res = abs(c - b) + abs(r - a);
       printf("%d\n",res);
    }
    return 0;
}

Uri 1276 - Letter Range

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

int main()
{
    int ans[27];
    string s;
    while(getline(cin,s)){
        memset(ans,0,sizeof(ans));
        set < char > res;
        int p = 0;
        for(int i = 0; i < s.size() ;i++){
            ans[s[i] - 'a'] = 1;
            res.insert(s[i]);
        }
        char ch = '#';
        for(int i = 0; i < 26 ;i++){
            if(ans[i]){
                if(ch == '#') ch = (char)(i+'a');
            }else{
                if(res.count(ch) != 0){
                    if((ch - 'a') - i == 1)
                         (p)? cout << ", " << ch << ":" << ch : cout << ch << ":" << ch;
                    else
                         (p)? cout << ", " << ch << ":" << (char) ((i-1)+'a') : cout << ch << ":" << (char)((i-1)+'a') ;
                p=1;
                }
                ch = '#';
            }
        }
        if(ch != '#')(p)?cout << ", " << ch << ":" << 'z' :cout << ch << ":" << 'z' ;
        cout << endl;
    }
    return 0;
}

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;
}

Friday, February 24, 2017

Uri 1766 - The Dark Elf

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

typedef struct{
    string name;
    string n_u_c;
    int weight, age ;
    float height;
}love;
love recods[1001];

bool cmp(love x, love y)
{
    if(x.weight == y.weight)
            if(x.age == y.age)
              if(x.height == y.height)
                 if(x.n_u_c != y.n_u_c)
                     return x.n_u_c < y.n_u_c;
                 else
                   return x.n_u_c > y.n_u_c;
               else
                  return x.height > y.height;
             else
                return x.age > y.age;
           else
             return x.weight < y.weight ;
}

int main()
{
    freopen("in.txt","r",stdin);
    string a,a1;
    int n,ca=0,l1,l2;

    cin >> n;
    cin.ignore(100,'\n');

    for(int j = 1 ;j <= n ;j++){
        cin >> l1 >> l2;

   for(int i = 0; i < l1 ;i++)
    {
      cin >> recods[i].name >> recods[i].weight >> recods[i].age >> recods[i].height;
      recods[i].n_u_c = recods[i].name;
      transform(recods[i].name.begin(),recods[i].name.end(),recods[i].n_u_c.begin(),:: toupper);
    }
    stable_sort(recods,recods+l1,cmp);
    reverse(recods,recods+l1);

    printf("CENARIO {%d}\n", j);

    for(int i = 0; i < l2; i++){
         printf("%d - ", i+1);
         cout << recods[i].name << endl;
    }
}
    return 0;
}

Uri 1258 - T-Shirts

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

typedef struct{
    string s1;
    string s2;
    char ch ;
}love;
love recods[1001];

bool cmp(love x, love y)
{
    if(x.s2 == y.s2){
        if(x.ch == y.ch) return x.s1 < y.s1;
        else return x.ch > y.ch;
    }else{
        return x.s2 < y.s2;
    }
}

int main()
{
    freopen("in.txt","r",stdin);
    string a,a1;
    int n,ca=0;
    char ch;
    while(cin >> n and n != 0){
            cin.ignore(100,'\n');

   if(ca != 0) cout << endl;

   for(int i = 0; i < n ;i++)
    {
        getline(cin,a);
        getline(cin,a1);

        recods[i].s1 = a;
        size_t p = a1.find(' ');
        recods[i].ch = a1[a1.size()-1];
        a1 = a1.substr(0,p);
        recods[i].s2  = a1;

    }
    stable_sort(recods,recods+n,cmp);

    for(int j = 0; j < n; j++)
          cout << recods[j].s2 << " " << recods[j].ch << " " << recods[j].s1 << endl;

            ca++;

    }
    return 0;
}

Thursday, February 23, 2017

Uri 2482 - Noel's Labels

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

int main()
{
    //freopen("in.txt","r",stdin);
    int n,k;
    string s,s1;
    map < string , string > ans;
    cin >> n;
    cin.ignore(100,'\n');
    for(int i = 0; i < n ;i++)
    {
        getline(cin,s);
        getline(cin,s1);
        ans.insert( pair < string , string > ( s , s1 ));
    }
    int i = 0;
    cin >> k;
    cin.ignore(100,'\n');
    while(i != k){
        getline(cin,s);
        if(i != 0) cout << endl;
        cout << s << endl;
        getline(cin,s1);
        cout << ans.find(s1)->second << endl;
        i++;
    }
    cout << endl;
    return 0;
}

Tuesday, February 21, 2017

Uri 1588 - Help the Federation

#include<bits/stdc++.h>
 using namespace std;
#define ZERO(x) memset(x, 0, sizeof(x))

typedef struct{
    char name[101] ;
    int t_p  ,t_w ,t_g  ,pos ;
}team;
team team_records[1001];

bool cmp(team x,team y){
    if(x.t_p != y.t_p)
        return x.t_p > y.t_p;
    if(x.t_w != y.t_w)
        return x.t_w > y.t_w;
    if(x.t_g != y.t_g)
        return x.t_g > y.t_g;
    return x.pos < y.pos ;
}

int position(int si, string s){
    for(int i = 0;  i < si ;i++)
    if(team_records[i].name == s)
        return i;
    return -1;
}


int main()
{
    freopen("in.txt","r",stdin);

    int n;
    cin >> n;
    while(n--)
    {
        int k,l,g_a,g_b;
        string  t_n2 , t_name1 , t_name2;
        char t_n1[101];

        cin >> k >> l;
        getchar();
        ZERO(team_records);

        for(int i = 0; i < k ; i++){
        scanf(" %[^\n]",team_records[i].name);
        }

        for(int i = 0; i < l ; i++){

        cin >> g_a >> t_name1 >> g_b >> t_name2;

        int t1,t2;
        t1 = position(k,t_name1);
        t2 = position(k,t_name2);

         if(g_a > g_b){
            team_records[t1].t_p += 3;
            team_records[t1].t_w++;
         }else if(g_a < g_b)
         {
             team_records[t2].t_p += 3;
             team_records[t2].t_w++;
         }else{
             team_records[t1].t_p += 1;
             team_records[t2].t_p += 1;
         }
         team_records[t1].t_g += g_a;
         team_records[t2].t_g += g_b;
        }
      stable_sort(team_records,team_records+k,cmp);

      for(int j = 0; j < k ;j++)
      cout << team_records[j].name << endl;

    }
    return 0;
}


Sunday, February 19, 2017

Uri 2408 - Vice-Campeão

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

int main()
{
    int a[3], t ;
     scanf("%d %d %d",&a[0],&a[1],&a[2]);
      sort(a,a+3);
     printf("%d\n",a[1]);
    return 0;
}

 

Uri 2410 - Frequencia na Aula

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

int main()
{
    int a, t ;
     map < int ,int > st;
     scanf("%d",&a);
     while(a--){
         scanf("%d",&t);
         if(st.count(t) == 0)
             st[t]++;
     }
     printf("%d\n",st.size());
    return 0;
}

Uri 2418 - Carnaval

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

int main()
{
    int a, t ;
    double ar[6];
    for(int i = 0; i < 5 ; i++)
       scanf("%lf",&ar[i]);
      
       sort(ar,ar+5);
      
      printf("%.1lf\n",ar[1]+ar[2]+ar[3]);
    return 0;
}

Uri 2416 - Corrida

#include<bits/stdc++.h>


 using namespace std;

int main()
{
    int a, t ;
    scanf("%d %d",&a,&t);
     printf("%d\n",a%t);
    return 0;
}

Uri 2415 - Consecutivos

#include<bits/stdc++.h>







using namespace std;

int main()
{
    int a,ans = 0 , t = 1;
    scanf("%d",&a);
    int ar[a+1];
   for(int i = 0; i < a ;i++){
       scanf("%d",&ar[i]);
              if(ar[i] == ar[i-1]) t++;
           else ans = max(ans,t) , t = 1;
   }
   ans = max(ans,t);
   printf("%d\n",ans);
    return 0;
}

Uri 2414 - Desafio do Maior Número

#include<bits/stdc++.h>
 using namespace std;
 
int main()
{
    int a,ans = 0;

   while(cin >> a and a != 0){
       ans = max(ans,a);
   }
    cout << ans << endl;

    return 0;
}

Uri 2413 - Busca na Internet

#include<bits/stdc++.h>



  using namespace std;

int main()
{
    int a;

    cin >> a;
    cout << (a*2)*2 << endl;

    return 0;
}

Uri 2424 - Tira-teima




#include<bits/stdc++.h>


   using namespace std;

int main()
{
    int a,b;

    cin >> a >> b ;
     if(a >= 0 and a <= 432 and b >= 0 and b <= 468)cout << "dentro" << endl;
     else cout << "fora" << endl;

    return 0;
}