Sunday, February 19, 2017

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

Uri 2451 - PacMan

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

int main()
{
    int n,m,i,j,k = 0,t,ans = 0;
    string s,s1;
    cin >> n;
    for(i = 0; i < n ; i++){
            cin >> s;
            if(i%2 != 0){
               reverse(s.begin(),s.end());
               for( j = i*n ,t = 0; j < (i+1)*n ; j++ , t++)
                 s1 += s[t];
               } else {
                for( j = i*n,t = 0; j < (i+1)*n ; j++,t++)
                 s1 += s[t];
               }

        s.clear();
       }
 for(i = 0; i < s1.size() ;i++){

    while(s1[i] != 'A'){
            if(s1[i] == 'o'){
             k++;
            }
            if(s1[i+1] == 'A' or s1[i] == '\0'){
                ans = max(ans,k);
                k = 0;
            }
          if(s1[i] == '\0') break;
    i++;
    }
 }
    cout << ans << endl;
    return 0;
}

Monday, February 13, 2017

Uri 2355 - Brazil and Germany

/*                                           Codeman
                                         Arif Khan Nihar
                                 Uri 2355 - Brazil and Germany

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

int main()
{
    unsigned long n;
    while(cin >> n and n != 0){
        double avg_g = n/90.0;
        int bra,gar;
        bra = floor(avg_g*1);
        gar = ceil(avg_g*7);

        cout << "Brasil " << bra << " x Alemanha " << gar << endl;
    }
    return 0;
}

Uri 2381 - Lista de Chamada

/*                                         Codeman
                                       Arif Khan Nihar
                             Uri 2381 - Lista de Chamada

 C++11 or C++14                                */

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

int main()
{
    string s;
    int n,k;
    set < string > name;
    cin >> n >> k;
    while(n--){
        cin >> s;
        name.insert(s);
    }
    int j = 1;
    for(const auto& i:name){
        if(j == k)
            return cout << i << endl , 0;
        j++;
    }
    return 0;
}

Uri 2374 - Pneu

/*                                                    Codeman
                                                 Arif Khan Nihar
                                                 Uri 2374 - Pneu

  */
#include<bits/stdc++.h>






using namespace std;
int main()
{
      int n ,m ;
      cin >> n >> m;
      cout << ((n != m)? n-m:0) << endl;
    return 0;
}

Uri 1785 - Kaprekar

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

// Highest number calculate
int highest_number_with_digits_of(int x1){
    int hi[4],i = 0;
    memset(hi,0,sizeof(hi));
    int tmp,res;
            while(x1 != 0){
            tmp = x1 % 10;
            x1 /= 10;
            hi[i] = tmp;

            i++;
        }
        sort(hi,hi+4);
        int e;
        for(int i = 0,j=3; i < 2 ;i++,j--){
            e = hi[j];
            hi[j] = hi[i];
            hi[i] = e;
        }

        res = (hi[0]*1000)+(hi[1]*100)+(hi[2]*10)+hi[3];
        return res;
}
//Lowest number calculate
int lowest_number_with_digits_of(int x2){
    int lo[4],i=0;
    memset(lo,0,sizeof(lo));
            int tmp,res;
            while(x2!=0){
            tmp = x2%10;
            x2 /= 10;
            lo[i] = tmp;
            i++;
        }
        sort(lo,lo+4);
        res = (lo[0]*1000)+(lo[1]*100)+(lo[2]*10)+lo[3];
        return res;
}

//ans counting
int krapekar(int x) {
   int cnt = 0;
   while (x != 6174) {
       int hi = highest_number_with_digits_of(x);
       int lo = lowest_number_with_digits_of(x);
       x = hi - lo;
       cnt = cnt + 1;
   }
   return cnt;
}
int main()
{
    int x_1,n,tmp1,test_case = 0;

    cin >> n;
    while(n--){

    int equ[4],i = 0;
    memset(equ,0,sizeof(equ));//array initilize
        int y = 1;

        cin >> x_1;
        tmp1 = x_1;
        //check every digits are equeal r not equal
        while(x_1 != 0){
            int tmp = x_1%10;
            x_1 /= 10;
            equ[i] = tmp;
            i++;
        }
        sort(equ,equ+4);

        if(equ[0] == equ[1] and equ[1] == equ[2] and equ[2] == equ[3]) y = 0;

        cout << "Caso #" << ++test_case << ": ";
        if(tmp1 == 0 or y == 0) cout << -1 << endl;
        else  cout << krapekar(tmp1) << endl;

    }
    return 0;
}

Sunday, February 12, 2017

Uri 2084 - Elections

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

int main()
{
    int n,m,t_v = 0;
    double percentage;
    int ar[10001];
    double p_v[10001];
    cin >> n;
    for(int i = 0; i < n ;i++){
        cin >> ar[i];
        t_v += ar[i];
    }
    sort(ar,ar+n);
    for(int i = 0; i < n ;i++){
        percentage = (ar[i]*100)/t_v;
        if(percentage >= 45.0)
            return cout << 1 << endl,0;
        p_v[i] = percentage;
    }

    if(p_v[n-1] < 40.0)
        return cout << 2 << endl , 0 ;

    for(int i = n-2 ; i >= 0 ;i--){
        if((double)(p_v[n-1] - p_v[i] ) <= 10.0)
             return cout << 2 << endl , 0 ;
    }

    cout << 1 << endl;
    return 0;
}

Uri 2180 - Travel to Mars in Primo Speed

include <bits/stdc++.h>  
using namespace std;
 
int n = 600010 ;
long ant = 0;
 int prime[300000];
 int nprime;
 int mark[1000002];
 //calculate prime number
void SieveOfEratosthenes(int n1)
{
int i,j,limit = sqrt(n*1.) + 2;
int l = 1;
mark[1] = 1;
for(i = 4; i <= n ;i += 2) mark[i] = 1;
prime[nprime++] = 2;

for(i = 3; l < 11 ;i += 2){
    if(!mark[i]){
        prime[nprime++] = i;
        if(i  <=  limit){
            for(j = i*i; j <=  n ;j += i*2){
                mark[j] = 1;
            }
        }
        if( i  >=  n1 ){
         ant += i,l++;
          }
    }
  }
}

int main() {
    int w;
    double v1,d;
    long n , x;
    int ans = 0,an = 0;
     cin >> w ;
    SieveOfEratosthenes(w);
    v1 = ceil(60000000/ant);
    d = floor(v1/24);
    cout << ant << " km/h" << endl;
    cout << v1 << " h / " << d << " d" << endl;
    return 0;
}