Tuesday, November 15, 2016

Codeforces Round #379 (Div. 2) 734 B - Anton and Digits

/*                          CODEMAN
                        Arif Khan Nihar
                    Problem -B. Anton and Digits
*/
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
    string s;
    int d2,d3,d5,d6,mi = 1000001,mi2 = 1000001,sum = 0;
    scanf("%d %d %d %d",&d2,&d3,&d5,&d6);
     mi = min(d2,min(d5,d6));
     sum += 256*mi;
     d2 -= mi , d5 -= mi, d6 -= mi;
     if(d2 != 0 and d3 != 0){
        mi2 = min(d2,d3);
        sum += 32*mi2;
     }
        cout << sum << endl;

    return 0;
}

Codeforces Round #379 (Div. 2) 734 A - Anton and Danik





#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n,a_s=0,d_s=0;
    char ch;
    cin >> n;
    while(n--){
        cin >> ch;
        if(ch  ==  'A') a_s++;
        else d_s++;
    }
    if(a_s < d_s)
        cout << "Danik\n";
    else if(a_s > d_s)
        cout << "Anton\n";
    else
        cout << "Friendship\n";
    return 0;
}

Saturday, November 12, 2016

Uva 10220- I Love Big Numbers !

/*                                                 CODEMAN
                                                ARIF KHAN NIHAR
                                        Uva 10220- I Love Big Numbers !
                                                 date -> 20/10/2016

                                            */
#include<bits/stdc++.h>
using namespace std;
string res[50001],sum[50001];

string add(string s1,string s2,int n1);

string multiply(string st1,int n){
          string s="";
    int l = 0 , c = 0 , ll = 0;
    for(int i = 0; i < st1.size() ; i++){
        l = ((st1[i]-48) * n)+l;
        if(l > 9)ll = l%10 , l/=10;
        else ll = l, l=0;
        s += (ll+48);
    }
    if(l != 0) s += (l+48) ;

    return s;
}
string convert_length(string sd,string st,int t){
    string ssd="",ssf="";
    for(int i = 0; i < st.size()+t ; i++){
            if(i < t)
            ssd += sd[i];
            else
            ssd += st[i-t];
    }
    ssf = add(sd,ssd,t);
    return ssf;
}
string add(string s1,string s2,int t1){
    string rs;
    int l=0,k=0,c=0;
    k = max(s1.size(),s2.size());
    for(int i = 0 ; i < t1 ; i++ ) rs += s2[i];
    for(int i = t1; 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 = (s1[i]-48)+(s2[i]-48) + c,c=0;
        }
        if(l > 9){
            l = l-10,c=1;
        }
        rs+= l + 48;
    }
    if(c == 1)rs+="1",c=0;
    return rs;
}

string prot(string s,string s1){
    int j,j1=0,p=0,l=0;
    string s4="";
    reverse(s.begin(),s.end());
     reverse(s1.begin(),s1.end());
     if(s.size() < s1.size())swap(s,s1);
                for( j = 0; j < s1.size(); j++ ){
                        res[j]=multiply(s,(s1[j]-48)),p++;
        }
        if(p == 1)
            s4 = res[0];
        else if(p == 2){
            s4 = convert_length(res[0],res[1],1);
        }
        else{
        for( j1 = 2; j1 <= p ; j1++,l++)
            res[j1-1] = convert_length(res[j1-2],res[j1-1],l+1);

        s4 = res[j1-2];
    }
        reverse(s4.begin(),s4.end());
        return s4;
}

string fac(int n){
    string s1,s2;int i=0;char ss[100001];
    bool b = true;
    sum[1] = "1";//sum[2] = "2";
    for( i = 2 ;i <= n ; i++ ){
            sprintf(ss,"%d",i);
        sum[i] = prot(sum[i-1],ss);
    }
    s1 = sum[i-1];
    return s1;
}

int main()
{
    //freopen("in.txt","r",stdin);
    int s,rs,i;
    string st = "";
    while(cin>>s){
            rs = 0;
    st = fac(s);
    for(i = 0; i < st.size() ; i++ ){
        rs += st[i]-48;
    }
    cout << rs << endl;

    for(i = 0 ; i < s ; i++ )
      res[i].clear(),sum[i].clear();
 }
    return 0;
}

Dev-skills -- Square Sum Difference

/*                         CODEMAN
                        Arif Khan Nihar
                Problem - Square Sum Difference

*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i,k,l=1;
   long long sum = 0 ,sumd = 0,ans ;
   int ar[45];
       cin >> n;
    while(n--){
            sum = 0 ,sumd = ans = 0,l = 1;
        cin >> k;
        while(l<=k){
            sumd += l;
            sum += l*l;
            l++;
        }

        ans = sumd*sumd - sum;
        printf("%lld\n",ans);
    }
    return 0;
}



Dev-skills -- Easy Sequence

/*                         CODEMAN
                        Arif Khan Nihar
                    Problem - Easy Sequence


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

Dev-skills -- My Merit Position

/*                         CODEMAN
                        Arif Khan Nihar
                Problem - My Merit Position
*/

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

struct man_records{
string t_name;
double v;
}team_records[101];

bool cmp(const man_records &x, const man_records &y){
if(x.v != y.v)
return x.v > y.v;
else
 return x.t_name < y.t_name;
}
int main()
{
      int n,k=1;
      cin  >>  n;
      for( int i = 0; i < n ;i++ ){
             cin >> team_records[i].t_name;
            cin >> team_records[i].v;
      }
      stable_sort(team_records,team_records+n,cmp) ;

      for ( int  i  =  0 ;  i < n ; i++)  {
            if(team_records[i].v == team_records[i-1].v)
                cout << k-1 << ".";
            else cout << k++ << ".";
          cout << team_records[i].t_name << endl;
      }

    return 0;
}

Dev-skills -- Break Simulator

/*                          CODEMAN
                            Arif Khan Nihar
                    Problem - Break Simulator


*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
double v,t,ans=0;
int n;
cin>>n;
while(n--) {
cin>>v>>t;
ans = (v/t)*(-1);
printf("%.2lf\n",ans);
   }
return 0;
 }

Friday, November 11, 2016

Uva 10579- Fibonacci Numbers

/*                                                CODEMAN
                                             ARIF KHAN NIHAR
                                    Uva 10579- Fibonacci Numbers


*/
#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[1]="1",num[2]="1";
for(int i = 3 ; i < 4787 ; i++ ) {
num[i] += make(num[i-2],num[i-1]);
}
while(cin>>n){
cout << num[n] << endl;
}
return 0;
}

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