Monday, February 13, 2017

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

Saturday, December 31, 2016

Toph - Word Count

#include
using namespace std;


char buff[101];
int main()
{
    map < string , int > tree ;
    while( gets(buff) ) {
        string str = buff;
        stringstream sin(str);
        string token;
        while(sin >> token){
            tree[token]++;
        }
    }
    string ans;
    int i = 0 , k = 0;
    for(map :: iterator it = tree.begin() ; it  != tree.end()  ; it++ , i++ ){
        if((it->second) > k and i != 0){
            k = it->second;
            ans = it->first;
        }
        if (i == 0) k = it->second , ans = it->first;
    }
cout << ans << endl;
    return 0;
}

Tuesday, December 27, 2016

hackerrank - Equalize the Array

#include<bits/stdc++.h>

using namespace std;

int main() {
    int a[101];
    int n , ans = 1,res = 0;
    cin >> n;
     for(int i = 0; i < n ;i++)
          cin >> a[i];
    sort( a,a+n );
    for(int i = 0; i < n-1 ;i++){
        if(a[i] == a[i+1]) ans++;
        else res = max(res,ans) , ans = 1;

    }
    res = max(res,ans);
    cout << n-res << endl;
    return 0;
}

Uri 2129 - Factorial

#include<bits/stdc++.h>
using namespace std;
//last non zero digit any factorial number function
long long fac(int a){
    int f[11] = {1,1,2,6,4,2,2,4,2,8,8};
        // mathematical equation
       // a/10 == odd  fac(a) = 4*fac(a/5)*fac(a%10)
      // a/10 == even  fac(a) = 6*fac(a/5)*fac(a%10)
    if(a < 11) return f[a];
    return ( ( a / 10 ) % 2 == 1?  4 : 6 ) * fac( a / 5 ) * fac ( a % 10 );      
}

int main()
{
    int n , i = 1;
    while(scanf("%d",&n) != EOF){
    printf("Instancia %d\n%d\n\n",i++,( fac(n) ) % 10);
    }
    return 0;
}

Monday, December 26, 2016

Uri 2312 - Medal Table

#include<bits/stdc++.h>
using namespace std;
struct match_records{
            string t_name;
            string t_name_uppercase;
            int g,s,b;

    }team_records[1001];

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

    return x.t_name_uppercase < y.t_name_uppercase;
}

int main()
{
    int n;
    scanf(" %d ", &n);

       for(int i = 0; i < n ;  i++) {
           char s[101];
         scanf("%s", s) ;
         scanf(" %d %d %d", &team_records[i].g,&team_records[i].s,&team_records[i].b);
         team_records[i].t_name = team_records[i].t_name_uppercase = s;
         transform(team_records[i].t_name.begin(),team_records[i].t_name.end(),
                  team_records[i].t_name_uppercase.begin(),:: toupper);
       }
      stable_sort(team_records,team_records+n,cmp);

      for(int i = 0; i < n ; i++) {
        cout << team_records[i].t_name << " " << team_records[i].g << " " << team_records[i].s << " " << team_records[i].b << endl;
      }


    return 0;
}

Uri 2336 - ABC

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007

vector < lli > v ;

lli add(){
    lli an = 1;
     int p  = 1001;
     v.push_back(1);
        while( p > 0 ) {
            an = (an * 26) %  mod ;
            v.push_back( an );
             p-- ;
        }
}
int main()
{
    add();

   string s,s1;
   lli a,b,sum = 0;
    while(cin >> s){
            sum = b = 0;
    int t  = s.size() - 1;
    for(int i = 0; i < s.size() ;i++ , t-- ){
        sum += ((s[i]-'A') * v[t]) % mod;
        sum %= mod;
    }
    cout << sum << endl;
    }
    return 0;
}


Uri 2313 - Which Triangle

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

int main()
{
    int a,b,c;
    string ans = "" ;
    cin >> a >> b >> c ;
    if( a + c > b ){
    if((a != b and b == c) or ( a == c and a != b) or ( a == b and c != b))
        ans = "Valido-Isoceles";
    else if(a == b and a == c)
        ans = "Valido-Equilatero" ;
    else if(a != b and b != c and a != c)
        ans = "Valido-Escaleno";
    }
    else{
        ans = "Invalido";
    }

    if(ans != "Invalido"){
      if( pow(a,2) == pow(b,2) + pow(c,2)
         or pow(b,2) == pow(a,2) + pow(c,2)
         or pow(c,2) == pow(a,2) + pow(b,2) )
         cout << ans << endl << "Retangulo: S" << endl ;
       else
         cout << ans << endl << "Retangulo: N" << endl;
    }
    else
        cout << ans << endl;

    return 0;
}

 

Friday, December 23, 2016

uri 2450 - Matrix Ladder

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,c,m;

    scanf("%d %d",&n,&m);
    int ppp = 0;
    bool bo,ok = true;
    for (i = 0; i < n; i++) {
             int  pp = 0;
             bo = true;
        for (j = 0; j < m; j++) {
             scanf("%d", &c);
             // count how many zero(0) in the row
             if(c ==  0 and bo) pp++;
             else bo = false;
        }
        // check the matrix is ladder matrix or not
        if( i != 0)
            if( (pp > ppp or (pp == ppp and pp == m)) and ok) ppp = pp;
             else{
                ppp = 0;
                ok = false;
             }
        else
            ppp = pp ;
    }
    cout << ((ppp)? "S\n" : "N\n") ;

    return 0;
}

hackerrank - Cut the sticks

#include<bits/stdc++.h>
using namespace std;
int main() {

    int n,k,l,m;
    vector < int > v;
    cin >> n;

    for(int i = 0; i < n ;i++) {
            int u;
            cin >> u;
            v.push_back(u);
    }
    sort(v.begin(),v.end());
    while(true){
        cout << v.size() << endl;
          if(v.size() == 1) break;
        int t = v[0];
        for(int i = 0; i < v.size() ; i++) {
                v[i] -= t;
        }
        for(; v.front() == 0;) {
                  v.erase(v.begin()+ 0);

        }
    }

    return 0;
}

hackerrank - Repeated String

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    long n,t , c = 0;
    int d ;
    cin >> a >> n;
    t = n/a.size();
    d = n%a.size();
     for(int i = 0; i < a.size()  ; i++)
         if(a[i] == 'a') c++;
      c  *=  t ;
     for(int i = 0 ; i < d ; i++) if(a[i] == 'a')  c++ ;

    cout << c << endl;

    return 0;
}

uri 2486 - C Mais ou Menos?

#include<bits/stdc++.h>

using namespace std;
int vitamin(string s){

    if( s == " suco de laranja" )
        return 120;
    else if (s == " morango fresco" )
        return 85;
    else if (s ==  " mamao")
        return 85;
    else if (s == " goiaba vermelha")
        return 70;
    else if(s == " manga")
        return 56;
    else if(s == " laranja")
        return 50;
     else
        return 34;

}

int main()
{

 int n,m;
    string a;

    while(cin >> n and n){
        int sum = 0;
            while(n--) {
        scanf("%d", &m);

        getline(cin , a);

        sum  +=  (m*(vitamin(a)));

        }

        if(sum >= 110 and sum <= 130)
            cout << sum << " mg" << endl;
        else if (sum > 130)
            cout << "Menos " << sum - 130 << " mg" << endl;
        else
            cout << "Mais " << 110 - sum << " mg" << endl;
    }
    return 0;
}

uri 2479 - Sorting Santa's List of Children

#include<bits/stdc++.h>
using namespace std;
int main()
{
    multiset < string > m_s ;
    multiset < string > :: iterator it ;
    string s;
    char ch ;
    int n,p_i = 0,n_i = 0;
    cin >> n;
    while(n--){
        cin >> ch >> s;
        (ch == '+')? p_i++ : n_i++;
        m_s.insert(s);
    }
    for(it = m_s.begin(); it != m_s.end(); it++)
         cout << *it << endl;
    printf("Se comportaram: %d | Nao se comportaram: %d\n",p_i,n_i);

    return 0;
}

uri 2484 - Abracadabra

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

int main()
{
    int n,m=0;
    string a;
    while(cin >> a){
        for(int i = 0 ; i < a.size() ; i++) {
            for(int j = 0 ; j < a.size() ; j++) {
                if(j < i)
                    cout << " ";
                else
                  if(j == a.size() - 1)
                    cout << a[j-i];
                  else
                    cout << a[j-i] << " ";
            }
            cout << endl;
        }
     cout << endl;
    }
    return 0;
}

uri 2483 - Merry Christmaaas!


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    string s = "Feliz nata";
    cin >> n;
    for(int i = 1;i < n; i++)
         s += 'a';
    cout  << s <<  "l!" << endl;

    return 0;
}

Friday, December 16, 2016

Uva 10903 - Rock-Paper-Scissors Tournament

/*                                                CODEMAN
                                              Arif Khan Nihar
                                Uva 10903 - Rock-Paper-Scissors Tournament
                                             date -> 16/12/2016

                                             */
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int p,m=0,p1,p2,k=0;
    string s1,s2;
    while(cin >> p){
            if(p == 0) break ;
            if(k != 0 ) cout << endl;
        cin >> m;
        m = m*p*(p-1)/2;
        int p_ar[p+2] , p_l[p+2] ;
        float ans ;
        memset(p_ar,0,sizeof p_ar);
        memset(p_l,0,sizeof p_l);
        while(m--){
            cin >> p1 >> s1 >> p2 >> s2;
            if(s1 == "paper" and s2 == "rock") p_ar[p1]+=1,p_l[p2] += 1;
            if(s2 == "paper" and s1 == "rock") p_ar[p2]+=1,p_l[p1] += 1;
            if(s1 == "scissors" and s2 == "paper") p_ar[p1]+=1,p_l[p2] += 1;
            if(s2 == "scissors" and s1 == "paper") p_ar[p2]+=1,p_l[p1] += 1;
            if(s2 == "scissors" and s1 == "rock") p_ar[p1]+=1,p_l[p2] += 1;
            if(s1 == "scissors" and s2 == "rock") p_ar[p2]+=1,p_l[p1] += 1;

        }
        char res;
        for(int i = 1; i<= p ;i++){
            ans = ((float)p_ar[i]/(p_ar[i]+p_l[i]));
            if(p_ar[i] == 0 and p_l[i] == 0)
                cout << '-' << endl;
            else
                cout << fixed << setprecision(3) << ans << endl ;
        }
        k = 1;
    }

    return 0;
}


Saturday, December 3, 2016

Uva 1225 - Digit Counting.cpp


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

int main() {
     int n,m,y = 0, t = 1;
    char s1[10001];
    int ve[10] = {0},x = 1;
    cin >> n;
    while(n--){
        t = 1;
          cin >> m;
        while(t <= m){
            y = t ;
           sprintf(s1 , "%d" ,y);
           int jh = strlen(s1);
           for( int b = 0; b < jh ; b++) ve[s1[b]-48]++;
            t++;
        }
        for(int i = 0; i < 10 ; i++){
            if(i < 9)
            cout << ve[i] << " ";
            else
            cout << ve[i];

            ve[i] = 0;
        }
        cout << endl;
    }
    return 0;
}

Uva - 12289 - One-Two-Three

#include < iostream >
#include < string.h >
using namespace std;

int main() {
  int n,i,j;
  char s1[6];
  cin >> n;
  while(n--){
      cin >> s1;
      if(strlen(s1) == 5){
          cout << "3" << endl;
      } else if((s1[0] == 'o' && s1[1] == 'n') || (s1[0] == 'o' && s1[2] == 'e') || (s1[1] == 'n' && s1[2] == 'e') ){
              cout << "1" << endl;
      } else{
              cout << "2" << endl;
      }
  }
    return 0;
}

Codeforce - 13A. Numbers

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

int main() {
         int n;
          cin >> n;
          int sum = 0,d =0;
           for(int i =2 ;i< n ;i++){
            int t,p;
            t = i;
            p = n;
             
            while(p!=0){
             sum += p%i;
             p/=i;
            }
            d++;
           }
           int g = __gcd(sum,d);

           cout<<sum/g<<'/'<<d/g<<endl;
         
 return 0;
}

Codeforce - B. Anton and Digits

/*                          CODEMAN
                        Arif Khan Nihar
                    Problem -B. Anton and Digits
*/
#include<bits/stdc++.h>
#define long long ll
//#define long int li
using namespace std;

int main()
{
    string s;
    int d2,d3,d5,d6,mi = 5000001,mi2=5000001,sum=0;
    cin>>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;
}

Wednesday, November 16, 2016

Uva 10106- Product

/*                                                CODEMAN
                                              Arif Khan Nihar
                                             Uva 10106- Product
                                             date -> 17/10/2016

                                             */
#include<bits/stdc++.h>
using namespace std;
string res[501];
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;
}

int main()
{
    string s,s1;
    while(cin >> s >> s1) {
            string ss = "",ss1 = "";
            if(s[0] != '0')
               ss = s;
             else{
                for (int i = 0; i < s.size() ; i++)
                    if(s[i] == '0' and ss.empty())
                       continue;
                    else ss += s[i];
             }
           if(s1[0] != '0')
               ss1 = s1;
             else{
                for (int i = 0; i < s1.size() ; i++)
                    if(s1[i] == '0' and ss1.empty())
                       continue;
                    else ss1 += s1[i];
             }
            if(ss.size() != 0 and ss1.size() != 0 )
            cout << prot(ss,ss1) << endl;
            else
            cout << "0" << endl;

           ss.clear(),ss1.clear();

    for(int i = 0 ; i < 501 ; i++)
      res[i].clear();
 }
    return 0;
}

Uva 10679 - I Love Strings!!

/*                                                CODEMAN
                                                Arif Khan Nihar
                                     Uva 10679 - I Love Strings!!

                                             */
#include<bits/stdc++.h>
using namespace std;
int main()
{
      string s,s1;
      int n,k;
      scanf("%d",&n);
      while(n--){
            cin >> s;
        scanf("%d",&k);
        while(k--) {
            string st = "";
            cin >> s1;
            for(int i = 0; i < s1.size() ; i++)
                st += s[i];

            if( s1 == st)
            cout << "y" << endl;
            else
            cout << "n" << endl;
        }
      }

    return 0;
}


Uva 612- DNA Sorting

/*                                                  CODEMAN
                                                 Arif Khan Nihar
                                            Uva 612- DNA Sorting
                              
                                             */
#include<bits/stdc++.h>
using namespace std;
struct match_records{
            string t_name;
            int n1;
    }team_records[101];

bool cmp(const match_records &x, const match_records &y)
{
  return x.n1 < y.n1;
}


int sorted(string s1){
    int t = 0;
    for(int i = s1.size()-1 ;i >= 1 ;i-- ) {
        for(int j = 0; j <= i-1 ; j++ ) {
            if( s1[j] > s1[j+1] ) {
                    swap( s1[j] , s1[j+1] ) ;
                t++;
            }
        }
    }

    return t;
}

int main()
{
    int n,i,m,x;

    scanf("%d",&n);
    while(n--){
        scanf("%d %d", &x , &m ) ;
        for(i = 0 ;i < m ; i++ ) {
            string s;
            cin >> s;
           team_records[i].t_name = s;
           team_records[i].n1 = sorted(s);
        }
        stable_sort(team_records,team_records+m,cmp);

        for(i = 0 ; i < m ; i++) {
            cout << team_records[i].t_name << endl;
        }
     if(n)cout << endl;
    }
    return 0;
}

Uva 355 - The Bases are Loaded

/*
                                                      CODEMAN
                                              ARIF KHAN NIHAR
                                       uva 355 - The Bases are Loaded

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

#define sf scanf
#define pf printf

char N[] = "0123456789ABCDEF";
int main()
{
   long long int d,n1,n,i,j,l;
   int b1,b2;
    string re = "";
    char s[101];
    while( sf("%d %d %s",&b1,&b2,&s) == 3) {
        string rt = s;
    if(rt != "0"){
    n = strlen(s);
      n1 =  n - 1, l = d = 0;
      for(i = 0 ; n1 >= 0 ; i++ , n1-- ) {
        if( !isalpha(s[i])  &&  (((s[i]-48) >=  0)  &&  (( s[i] - 48)  <  b1)) ) {
        l += ((s[i]-'0') * (powl(b1,n1))) ;
        }
        else if(isalpha(s[i]) &&  ((( s[i] - 65 + 10) >=  0)  && ( s[i] - 65 + 10 ) < b1)) {
        l += (10 + (s[i] - 65)) * powl(b1,n1) ;
        }else{
            l = 0;
            break;
        }
       }
      if( l ){
      while( l )
        re += (N[l%b2]) , l /= b2 ;
    }
}else{
    re +=  "0";
}
    if( !re.empty() ){
      reverse(re.begin(),re.end());
      cout << s << " base " << b1 << " = " << re << " base " << b2 << endl;
    }else{
        cout << s << " is an illegal base " << b1 << " number" << endl;
    }

      re.clear();
    }

    return 0;
}


(devskills)Number Sort .cPP

/*                                       CODEMAN
                                      Arif Khan Nihar
                                  Problem - Number Sort

                                   */

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

struct match_records{
            string t_name;
            double n;

    }team_records[1001];

bool cmp(const match_records &x, const match_records &y)
{
  return x.n < y.n;
}

int main()
{
    int n,k;
    scanf(" %d ", &n);
    while(n--) {
       scanf("%d", &k);
       for(int i = 0; i < k ;  i++) {
            double kl;
           char s[9];
           char *p;
          scanf("%s", s) ;
        kl = strtod(s, &p) ;
        team_records[i].n = kl;
        team_records[i].t_name = s;
       }
      stable_sort(team_records,team_records+k,cmp);

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

    return 0;
}

(devskills)Not Easy But Not Hard .cPP

/*                                       CODEMAN
                                      Arif Khan Nihar
                              Problem - Not Easy But Not Hard

                                   */

#include<bits/stdc++.h>
using namespace std;
int main()
{
       int n;
    long long int k,ans;
    cin >> n;
    while( n-- ) {
            ans = 0;
            cin >> k;
       ans =  ( k* ( k + 1 )) / 2;
       cout << ans << endl ;

    }
    return 0;
}

(devskills)POS System.cPP

/*                                       CODEMAN
                                        Arif Khan Nihar
                                   Problem - POS System

                                   */

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

int main()
{
    double p1,amount;
    int q1,ans,n,k,g_a;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
            amount = 0;
            cin >> k;
    while( k-- ) {
        cin >> p1 >> q1;
        amount  +=  (p1*q1);
        }
    cin  >>  g_a;
    cout << "Case " << i << ": " << (int)(g_a - amount) << endl ;
    }
    return 0;
}