Friday, November 11, 2016

Uva 10469 - To Carry or not to Carry

/*
                                                      CODEMAN
                                                ARIF KHAN NIHAR
                                      uva 10469 - To Carry or not to Carry

*/
#include <stdio.h>
int main(){
unsigned int a, b;
while(scanf("%u %u", &a, &b) != EOF){
printf("%u\n", a ^ b);
}
return 0;
}

Uva 10450- World Cup Noise

/*                                              CODEMAN
                                            ARIF KHAN NIHAR
                                       Uva 10450- World Cup Noise
                                             date -> 20/10/2016

*/
#include<bits/stdc++.h>
using namespace std;
string num[5001];
string make(string s1,string s2){
string res;
int l=0,k=0,c=0;
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
k = max(s1.size(),s2.size());
for( int i = 0 ; i < k ; i++ ) {
if(i  > s1.size()-1) {
l = s2[i]-48 + c,c=0;
}else if(i > s2.size()-1) {
l = s1[i]-48 + c,c=0;
}else {
l = l = (s1[i]-48)+(s2[i]-48) + c,c=0;
                 }
if(l > 9) {
l = l-10,c=1;
               }
res+= l + 48;
            }
if(c == 1) res +="1",c=0;
reverse(res.begin(),res.end());
return res;
         }
int main(){
//freopen("in.txt","r",stdin);
int n1,n,i=1;
num[0]="1",num[1]="2";
for(int i = 2 ; i < 55 ; i++ ) {
num[i] += make(num[i-2],num[i-1]);
         }
cin>>n1;
while(n1--) {
cin>>n;
printf("Scenario #%d:\n",i);
cout << num[n] << "\n\n";
i++;
              }
return 0;
          }

Uva 10420 - List of Conquests

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,k,l,m;
string s,s2;
mapint
>res;
cin>>n;
while(n--) {
cin>>s;
getline(cin,s2);
res[s]++;
}
map < string,int > ::iterator it;
for(it = res.begin() ; it != res.end() ; it++ ) {
cout << (*it).first << " " << (*it).second;
cout << endl;
}
return 0;
}

Uva 10340 - All in All

#include<bits/stdc++.h>
using namespace std;
int main()
{
int m=0,i,j,k;
string s,s1,s2;
while(cin>>s >>s1){
k=m=0;
for(j = 0 ; j < s.size() ; j++ ) {
k=0;
for( i = m ; i < s1.size() ; i++ ) {
if(s[j] == s1[i]){
k = 1;
m=i+1;
break;
           }
      }
if(!k)break;
   }
if(k)  cout << "Yes\n";
else  cout << "No\n";
  }
return 0;
 }

Uva 10334- Ray Through Glasess

/*                                             CODEMAN
                                         ARIF KHAN NIHAR
                              Uva 10334- Ray Through Glasess
                                          date -> 20/10/2016

*/
#include<bits/stdc++.h>
using namespace std;
string num[5001];
string make(string s1,string s2){
string res;
int l=0,k=0,c=0;
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
k = max(s1.size(),s2.size());
for( int i = 0 ; i < k ; i++ ) {
if(i  >  s1.size()-1) {
l = s2[i]-48 + c,c=0;
         } else if( i  >  s2.size()-1 ) {
l = s1[i]-48 + c,c=0;
     }else{
l = l = (s1[i]-48)+(s2[i]-48) + c,c=0;
         }
if( l > 9 ) {
l = l-10,c=1;
          }
res+= l + 48;
        }
if(c == 1) res+="1",c=0;
reverse(res.begin(),res.end());
return res;
      }
int main(){
int n ;
num[0]="1",num[1]="2";
for( int i = 2 ; i < 1001 ; i++ ) {
num[i]  +=  make(num[i-2],num[i-1]);
             }
while( cin >> n  &&  n < 1001) {
cout << num[n] << endl;
          }
return 0;
     }

Uva 10327 - Flip Sort

#include<bits/stdc++.h>
using namespace std;
int n;
int ad[1005],bd[1001];
int check(int a){
int h = 0,l=0;
for(int i = a ; i >= 0 ; i-- ) {
if(ad[i] < ad[i-1]) {
h++;
swap(ad[i-1],ad[i]);
}
}
return h;
}
int main()
{
int i,j,k,l,m;
while(scanf("%d",&n)!=EOF){
l=0;
for( i = 0 ; i < n ; i++ ) {
cin>>ad[i];
if(i!=0)
if(ad[i] < ad[i-1]) swap(ad[i-1],ad[i]),l++;
}
for( i = 1 ; i < n ; i++ ) {
l += check(i);
}
printf("Minimum exchange operations : %d\n",l);
}
return 0;
}

Uva 10300 - Ecological Premium

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,ad[3],i,j;
cin >> n;
while(n--) {
int sum=0,k;
cin >> k;
while(k--) {
cin>>ad[0]>>ad[1]>>ad[2];
sum += ad[0]*ad[2];
                }
cout << sum << endl;
            }
return 0;
       }

Uva 10219- Find The ways!

/*                                                     CODEMAN
                                                 ARIF KHAN NIHAR
                                            Uva 10219- Find The ways!
                                                   date -> 10/20/2016

*/
#include<bits/stdc++.h>
using namespace std;
#define logdiv(n) log(n)/log(10)
int main()
{
double re;
long n,k;
while(cin>>n>>k) {
re = 0;
for( int i = 0 ; i < k ; i++ ) {
re += logdiv(n-i) - logdiv(i+1) ;
             }
cout << floor(re)+1 << endl;
         }
return 0;
     }

Uva 102 - Ecological Bin Packing

#include <iostream>
#include <string>
using namespace std;
int main (void) {
unsigned int bottles[9];
int bcg[9],bgc[9],cbg[9],cgb[9],gcb[9],gbc[9],i;
while (cin >> bottles[0]) {
int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,sum6=0;
string minimum = "BGC";
for ( i = 1; i < 9; i++) {
cin >> bottles[i];
bcg[i]=bottles[i],bgc[i]=bottles[i];
cgb[i]=bottles[i],cbg[i]=bottles[i];
gcb[i]=bottles[i],gbc[i]=bottles[i];
     }
bcg[0]=0,bgc[0]=0,bcg[5]=0,bcg[7]=0,bgc[4]=0,bgc[8]=0;
cbg[0]=bottles[0],cgb[0]=bottles[0],cbg[2]=0,cbg[3]=0;cbg[7]=0,cgb[2]=0,cgb[6]=0,cgb[4]=0;
gcb[0]=bottles[0],gbc[0]=bottles[0],gbc[8]=0,gcb[1]=0,gcb[5]=0,gcb[6]=0,gbc[1]=0,gbc[3]=0;
unsigned int min = 1 << 31;
for( i = 0 ; i < 9 ; i++ ) sum1+=bcg[i],sum2+=bgc[i],sum3+=cbg[i],sum4+=cgb[i],sum5+=gbc[i],sum6+=gcb[i];
if (sum1 < min)minimum = "BCG",min = sum1;
if (sum2 < min)minimum = "BGC",min = sum2;
if (sum3 < min)minimum = "CBG",min = sum3;
if (sum4 < min)minimum = "CGB",min = sum4;
if (sum5 < min)minimum = "GBC",min = sum5;
if (sum6 < min)minimum = "GCB",min = sum6;
cout  <<  minimum  <<  " " <<  min  <<  endl;
}
return 0;
}

Uva 10194 - Football (aka Soccer)

/*                                                                 CODEMAN
                                                                  Arif Khan Nihar
                                                     Uva 10194 - Football (aka Soccer)
                                                                date -> 22/10/2016

*/
#include<bits/stdc++.h>
using namespace std;
int match_result(int a,int b){
     if(a  > b) return 1;
     else if(a == b) return 0;
     else return -1;
}

struct match_records{
            string t_name;
            string t_name_uppercase;
            int t_points,t_goal,t_w,t_t,t_l,t_g_eat,t_p_m;

    }team_records[51];

string oneTotwo(string s){
    size_t p;string s1;
    p = s.find('#');
    s1 = s.substr(0,p);
    return s1;
}

string oneTotwore(string s){
    reverse(s.begin(),s.end());
        size_t p;string s1;
        p = s.find('#');
        s1 = s.substr(0,p);
        reverse(s1.begin(),s1.end());
       return s1;
}

int value(string s1){
    size_t p;string s2;
    p = s1.find('#');
    s2 = s1.substr(1+p);
    int n = 0;
    istringstream(s2) >> n;
    return n;
}

int value1(string s1){
    size_t p;string s2;
    p = s1.find('#');
    s2 = s1.substr(0,p);
    int n = 0;
    istringstream(s2) >> n;
    return n;
}

int check(string a,int n){
    int k = 0;
    for(int i = 0; i < n ; i++ ){
        if(a == team_records[i].t_name){
            k = i;
            break;
        }
    }
   return k;
}

bool cmp(const match_records &x, const match_records &y){

  if (x.t_points != y.t_points)
       return x.t_points > y.t_points;

  if (x.t_w!= y.t_w)
       return x.t_w > y.t_w;

  if (x.t_goal - x.t_g_eat != y.t_goal - y.t_g_eat)
       return x.t_goal - x.t_g_eat > y.t_goal - y.t_g_eat;

  if (x.t_goal != y.t_goal)
       return x.t_goal > y.t_goal;

  if (x.t_p_m != y.t_p_m)
       return x.t_p_m < y.t_p_m;

  return x.t_name_uppercase < y.t_name_uppercase;

}

int main()
{

  int n,t_num,i,j,t_m_num;
  string touranment_name,team_name;
  string s2,s3;char ss[101];
  size_t p , p1;

  cin >> n;
  cin.ignore(101,'\n');
  while(n--){
    getline(cin,touranment_name);
    cin >> t_num;
    cin.ignore(101,'\n');

    for( i = 0 ; i < t_num ; i++ ) {
         getline(cin,team_records[i].t_name);
         team_records[i].t_name_uppercase = team_records[i].t_name;
         transform(team_records[i].t_name.begin(),team_records[i].t_name.end(),team_records[i].t_name_uppercase.begin(),:: toupper);
    }

    cin >> t_m_num;
    cin.ignore(101,'\n');

    for( i = 0 ; i < t_m_num ; i++ ){
        getline(cin,s2);

        p = s2.find('@');
        s3 = s2.substr(0,p);
        s2 = s2.substr(p+1);

        string f_t_n = oneTotwo(s3);
        string s_t_n = oneTotwore(s2);

        int f_t_g_n = value(s3);
        int s_t_g_n = value1(s2);

        int k1 = 0;
        k1 = check(f_t_n,t_num);
        team_records[k1].t_p_m ++;

        int k2 = 0;
        k2 = check(s_t_n,t_num);
        team_records[k2].t_p_m ++;

    team_records[k1].t_goal += f_t_g_n;
    team_records[k1].t_g_eat += s_t_g_n;
    team_records[k2].t_goal += s_t_g_n ;
    team_records[k2].t_g_eat += f_t_g_n;

    if(match_result(f_t_g_n,s_t_g_n)>0){
        team_records[k1].t_w += 1;
        team_records[k1].t_points +=3;
        team_records[k2].t_l +=1;
    }
    else if(match_result(f_t_g_n,s_t_g_n)==0){
        team_records[k1].t_t +=1;
        team_records[k2].t_t +=1;
        team_records[k1].t_points +=1;
        team_records[k2].t_points +=1;
    }
    else{
        team_records[k2].t_w += 1;
        team_records[k2].t_points +=3;
        team_records[k1].t_l +=1;
      }
   }
    stable_sort(team_records,team_records+t_num,cmp);

    cout<    for (int i = 0; i < t_num; i++) {
      cout << i+1 << ") " << team_records[i].t_name << " " << team_records[i].t_points << "p, " << team_records[i].t_p_m << "g (" << team_records[i].t_w << "-" << team_records[i].t_t << "-" << team_records[i].t_l << "), " << team_records[i].t_goal - team_records[i].t_g_eat << "gd (" << team_records[i].t_goal << "-" << team_records[i].t_g_eat << ")" << endl;
      team_records[i].t_name.clear(),team_records[i].t_points = 0,team_records[i].t_p_m = 0,team_records[i].t_w = 0,team_records[i].t_t = 0,team_records[i].t_goal = 0,team_records[i].t_l = 0,team_records[i].t_g_eat = 0;
    }

   if(n)cout << endl;
  }

    return 0;
}