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

Uri 2423 - Receita de Bolo

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

int main()
{
    int a,b,c,mi = -100;

    cin >> a >> b >> c;
      a /= 2,b /= 3,c /= 5;

    mi = min(a,min(b,c));

    cout << mi << endl;

    return 0;
}

Uri 2353 - Just in Time

/*                                     Codeman
                                   Arif Khan Nihar
                                Uri 2353 - Just in Time

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

long primeCheck(long x){

    if(x%2 == 0) x -= 1;
    for(int i = x; i >= 2 ;i-= 2){
            bool b = true;
            for(int j = 3 ; j <=(i+1)/2; j += 2){
                if( i%j == 0 or i%2 == 0) {
                        b = false;
                        break;
                }
            }
            if(b) return i;
    }
}
int main()
{
    long n;
    cin >> n;
    cout << ((n == 2)? 2 : primeCheck(n)) << endl;

    return 0;
}

Dev Skill Journey By Circle (DCP-251)

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

int main()
{
    int n;
    long r1,r2;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%ld %ld",&r1,&r2);
        cout << 2*((r1*r2)/__gcd(r1,r2)) << endl;
    }
    return 0;
}

Dev Skill Write an algorithm (DCP-219)

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

int main()
{
    //freopen("in.txt","r",stdin);
     int x1,y1,y2,x2,n;
     char ch;
     while(cin >> n){
            int rp1 = 0,rp2 =0 ,rp3 = 0, rp4 = 0,tt = 1;
            map < string , int > op1,op2,op3,op4;
        for(int i = 1 ; i <= n ;i++){
                int ans = 0;
            scanf("%d %c %d",&x1,&ch,&y1);
            string s = "",s1 = "";
            s += x1+48,s += (char)ch,s += y1+48;
            s1 += y1+48,s1 += (char)ch,s1 += x1+48;
            if(ch == '+'){
                 if(op1.count(s)!= 0){
                    printf("Instruction %d: repeat step %d\n",i,op1.find(s)->second);
                 }else if(op1.count(s1) != 0){
                     printf("Instruction %d: repeat step %d\n",i,op1.find(s1)->second);
                 }else{
                     printf("Instruction %d: add %d to %d\n",i,x1,y1);
                     op1.insert(pair < string , int >(s,tt));
                     tt++;
                 }
            }else if (ch == '-'){
                if(op2.count(s) != 0){
                    printf("Instruction %d: repeat step %d\n",i,op2.find(s)->second);
                    rp2++;
                 }else{
                     printf("Instruction %d: subtract %d from %d\n",i,y1,x1);
                     op2.insert(pair < string , int > (s,tt));
                     tt++;
                 }
            }else if(ch == '*'){
                if(op3.count(s) != 0){
                    printf("Instruction %d: repeat step %d\n",i,op3.find(s)->second);
                    rp3++;
                 }else if(op3.count(s1) != 0){
                     printf("Instruction %d: repeat step %d\n",i,op3.find(s1)->second);
                     rp3++;
                 }else{
                     printf("Instruction %d: multiply %d with %d\n",i,x1,y1);
                     op3.insert(pair < string , int > (s,tt));
                     tt++;
                 }
            }else if(ch == '/'){
                if(op4.count(s) != 0){
                    printf("Instruction %d: repeat step %d\n",i,op4.find(s)->second);
                    rp4++;
                 }else{
                     printf("Instruction %d: divide %d by %d\n",i,x1,y1);
                     op4.insert(pair < string , int > (s,tt));
                     tt++;
                 }
            }
          }
        }
    return 0;
}

Dev Skill DCP-254(Cube Game )

#include<bits/stdc++.h>  
using namespace std;
#define read freopen("in.txt","r",stdin)
#define pb push_back
#define rv reverse(s.begin(),s.end())
#define pf push_front
#define lli long long int
#define li long int

int main()
{
    int n,t,b,s,g,r,i = 0;
    long ma = -1111111111;
    cin >> n;
    while(n--){
            long t = 0;
        scanf("%d %d %d %d",&b,&s,&g,&r);
        t = (1*b) + (3*s) + (10*g) + (-5*r);
         ma = max(ma,t);
         if(t < 0) t = 0;
         printf("Player %d: %ld\n",++i,t);
    }
    printf("High Score = %ld\n",ma);
    return 0;
}

Uri 2018 - Christmas Olympics

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

struct record{
    string t_name;
    string t_name_upper;
    int g,sl,b;
}team_records[1001];

bool cmp(const record &x, const record &y)
{
    if(x.g != y.g)
        return x.g > y.g;
    if(x.sl != y.sl)
        return x.sl > y.sl;
    if(x.b != y.b)
        return x.b > y.b;

    return x.t_name < y.t_name_upper;
}

int main()
{
    //freopen("in.txt","r",stdin);
    map g,sl,b;
    string s,s1;
    while(getline(cin,s)){
            for(int i = 1 ;i <= 3 ;i++)
            {
                 getline(cin,s1);
                 if(i == 1)
                    g[s1]++ , sl.insert(pair(s1,0)) , b.insert(pair(s1,0));
                 else if(i == 2)
                    sl[s1]++ , g.insert(pair(s1,0)) , b.insert(pair(s1,0));
                 else
                    b[s1]++ , g.insert(pair(s1,0)) , sl.insert(pair(s1,0));
            }
    }
          int i = 0;
         for( map :: iterator it = g.begin() , it1 = sl.begin(), it2 = b.begin() ; it != g.end() ; it++ , it1++ , it2++ , i++){

            team_records[i].t_name = team_records[i].t_name_upper = it->first;
            transform(team_records[i].t_name.begin(),team_records[i].t_name.end(),team_records[i].t_name_upper.begin() , ::toupper);
            team_records[i].g = it->second;
            team_records[i].sl = it1->second;
            team_records[i].b = it2->second;
         }
         stable_sort(team_records,team_records+i,cmp);
         int k = i;
         cout << "Quadro de Medalhas" << endl;
         for( i = 0; i < k ; i++)
            cout << team_records[i].t_name << " " << team_records[i].g << " " <<  team_records[i].sl << " "  << team_records[i].b << endl;
    return 0;
}

Friday, February 17, 2017

Uri 2448 - Postman

/*                                      CODEMAN
                                     Arif khan Nihar
                                   Uri 2448 - Postman

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

int main()
{
    int n,m,k = 0,l = 0,i,j,x,y,res = 0;
    map < long , int > ma;
    queue < long > S;
    cin >> m >> n;
        for(i = 0;i < m;i++){
        cin >> x;
        ma.insert(pair < long ,int > (x,i));
    }
     for(i = 0;i < n;i++){
        cin >> x;
        S.push(x);
    }
      while( !S.empty() ){
        x = S.front();
        if(ma.count(x) != 0){
         k = ma.find(x)->second;
        res += abs(l - k);
            l = k;
            S.pop();
     }
 }
    cout << res << endl;

    return 0;
}

Uri 2452 - Semente

/*                                      CODEMAN
                                     Arif khan Nihar
                                   Uri 2452 - Semente

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

int main()
{
    int n,k = 0,ans = 0,l,i,j,x,y,res=0,p = 0;
    queue < int > pq;
    int a[100001];
        cin >> j >> y;
    for(i = 0;i < y;i++){
            cin >> k;
            pq.push(k);
        }
        a[0] = 1;
        for(i = 1;i <= j;i++){
            a[i] = 0;
        }
        l = i = y;
         k = 0;
    while(!pq.empty()){
           x = pq.front();
           res++;
           pq.pop();

            a[x] = 1;
            if(a[x-1] == 0 and x-1 > 0)
            pq.push(x-1),k++,a[x-1] = 1;
            if(a[x+1] == 0 and x+1<= j)
            pq.push(x+1),k++,a[x+1] = 1;

            if(res == l){
                l = k;
                k = 0;
                if(p != 0)
                ans++;
                res = 0;
                p++;
            }
    }
    cout << ans << endl;
    return 0;
}