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

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

Saturday, February 11, 2017

Uri 2033-Interest on Loan

#include<bits/stdc++.h>




using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    int n,i,m;
    double m_a,i_r;
    while( cin >> m_a >> i_r >> m){
        double s,c,d;
        //simple interest
        s = (m_a*i_r)*m;
        //Compound interest
        c =  m_a* (powl((1+i_r),m)) - m_a;
        //interest difference
        d = abs(s-c);
        cout << "DIFERENCA DE VALOR = " << fixed << setprecision(2) << d << endl;
        cout << "JUROS SIMPLES = " << fixed << setprecision(2) << s << endl;
        cout << "JUROS COMPOSTO = " << fixed << setprecision(2) << c << endl;
    }

    return 0;
}

Uri 1869 - Base 32

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

int main()
{
    //freopen("in.txt","r",stdin);
    unsigned long long int n;
    string ar = "0123456789ABCDEFGHIJKLMNOPQRSTUV",ans;
    while(cin >> n ){
            if(n == 0) {
                    cout << 0 << endl;
            break;
            }else{
            while(n != 0){
            ans += ar[n%32];
              n /= 32;
            }
            reverse(ans.begin(),ans.end());
            cout << ans << endl;
            ans.clear();
            }
    }
    return 0;
}

Friday, February 10, 2017

Uri 2091 - Lonly Number

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

int main()
{
    int n;
    while(cin >> n and n != 0){
           map < string , int > m_p;
            string s;
    for(int i = 0; i < n ;i++) {
            cin >> s;
            m_p[s]++;
    }
    for(map < string , int > :: iterator it =  m_p.begin() ;  it  !=  m_p.end() ; it++ )
    {
        if((it->second) & 1 ) {
            cout <<  it->first  << endl;
            break;
        }
       }
    }
    return 0;
}

Uri 2022 - Christmas Gifts

#include
using namespace std;

struct shopping_recods1{
    string product_name1;
    string t_u_n1;
    double p1;
    int quntity;

}per_person_recod1[1001];

bool cmp1(const shopping_recods1 &x , const shopping_recods1 &y){
    if(x.quntity != y.quntity)
        return x.quntity > y.quntity;
    if(x.p1 != y.p1)
        return x.p1 < y.p1;
    return x.t_u_n1 < y.t_u_n1;
}
int main()
{
    string s1,s2;
    double ret;
    int n,m;
    while(cin >> s2 >> n){

            for(int i = 0; i < n ;i++){
                    cin.ignore(100,'\n');
                    getline(cin,s1);
         per_person_recod1[i].product_name1 = per_person_recod1[i].t_u_n1 = s1;
        transform(per_person_recod1[i].product_name1.begin(),per_person_recod1[i].product_name1.end(),per_person_recod1[i].t_u_n1.begin(), :: toupper);
        cin >> ret >> m;
        per_person_recod1[i].p1 = ret;
        per_person_recod1[i].quntity = m;
            }
        stable_sort(per_person_recod1,per_person_recod1+n,cmp1);

        cout << "Lista de " << s2 << endl;
        for(int i = 0; i < n ;i++){
             cout << per_person_recod1[i].product_name1 << " - R$" <             per_person_recod1[i].product_name1.clear();
             per_person_recod1[i].p1 = 0;
        }
        cout << endl;
    }
    return 0;
}

Uri 2136- Friends of Habay

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

int main()
{
    //freopen("in.txt","r",stdin);
    string s,ans,s1;
    set< string >s_y,s_n;
    int a=0;
    while(cin >> s and s != "FIM"){
            cin  >> s1 ;
        (s1 == "YES")? s_y.insert(s):s_n.insert(s);
        if(a == 0)
            a = s.size();
        else if(a < s.size() and s1 == "YES"){
            a = s.size();
            ans = s;
        }
    }
    for(set::iterator it = s_y.begin(); it != s_y.end() ;it++){
        cout << *it << endl;
    }
    for(set::iterator it = s_n.begin(); it != s_n.end() ;it++){
        cout << *it << endl;
    }
    cout << "\nAmigo do Habay:\n";
    cout << ans << endl;
    return 0;
}

Uri 1077 - Infix to Posfix

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

//set operator gread
int opV(char op1){
    if(op1 == '+' or op1 == '-') return 1;
    else if(op1 == '*' or op1 == '/') return 2;
    else if(op1 == '^') return 3;
}
//check operator gread
bool opre(char op1,char op2){
    return (opV(op1) >= opV(op2)) ? true:false;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    while(n--){
    //stack declar for operator menu ex(+,-,*,/,^ or spcal key (#,@,$))
    stackop_s;
    string s1;
    string s;
    cin >> s;
    for(int i = 0; i < s.size();i++){
        //operand
        if( (s[i] >= 'A' and s[i] <= 'Z') or (s[i] >= 'a' and s[i] <= 'z') or (s[i] >= '0' and s[i] <= '9') )
             s1 += s[i];
    //operator
        else if((s[i] == '+' or s[i] == '-' or s[i] == '*' or s[i] == '/' or s[i] == '^')){
                while( !op_s.empty() and opre(op_s.top(),s[i]) and op_s.top() != '('){
                    s1 += op_s.top();
                    op_s.pop();
                }
                op_s.push(s[i]);
            }else if((s[i] ==  ')' )){
               while( !op_s.empty() and op_s.top() != '(' ){
                     s1 += op_s.top();
                     op_s.pop();
               }
               op_s.pop();
        }else if( s[i]  ==  '(' ){
                 op_s.push(s[i]);
                 }
    }
    while(!op_s.empty()){
             s1 += op_s.top();
             op_s.pop();
    }
    cout << s1 << endl;
    }
    return 0;
}

Thursday, February 9, 2017

Uri - 2334 Little Ducks

#include
using namespace std;

int main()
{
    string n;
    while(cin >> n  and  n  !=  "-1"){
        int t = 0;
        if(n  == "0") cout  <<  "0"  <<  endl;
        else {
            if(n.size()>1){
            for(int i = n.size()-1; i >= 0;i--){
                if(n[i] != '0'){
                    t = i;
                    break;
                }
            }
            for(int i = 0 ;  i < n.size() ;i++){
                if(i  < t)
                cout << n[i];
                else if(i == t) {
                    if (n[i] !=  '1' ) cout  <<  n[i]-'1 ';
                    if(n[i]  ==  '1' and i  !=  0) cout  <<  "0" ;
                }
                else cout << '9';
                }
            }else{
                cout  <<  n[0]-'1';
            }
               cout  <<  endl;
        }
    
        n.clear();
    }
    return 0;
}