Friday, April 7, 2017

Uri 2252 - Discovering Password

#include <bits/stdc++.h>
using namespace std;
typedef long double LD;

template
struct less_first {
    typedef pair < T1, T2 > type;
    bool operator ()(type const& a, type const& b) const {
        return a.first > b.first;
    }
};

int main()
{
    //freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,c = 0;
    while(cin >> n){
        map < LD, int > ans;
        LD a;
        for(int i = 0; i < 10 ;i++) {
                cin >> a;
         while(ans.count(a) != 0){
            a -= (LD)1e-15;
         }
        ans.insert(pair < LD,int > (a,i));
        }
     vector < pair < LD, int > > ans1(ans.begin(), ans.end());
     sort(ans1.begin(), ans1.end(), less_first < LD, int > ());
     vector > :: iterator it = ans1.begin();

     int i = 0;
     cout << "Caso " << ++c << ": ";
     for( vector < pair < LD, int > > :: iterator it = ans1.begin() ; it != ans1.end() ;it++,i++){
        if(i == n) break;
        cout << it->second ;
     }
        cout << endl;
    }
    return 0;
}

Uri 1945 - Simulator

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    string s;
    map < string , int > ans;
    int res;
    while(getline(cin,s)){

    stringstream str1(s);
    vector < string > variable;
    string take;
    while (str1 >> take)
    variable.push_back(take);

        int l = variable.size();

        if(l == 3){
        string ds = variable[2];

        if(isdigit(ds[0])){
            stringstream str2(variable[2]);
            int p = 0;
            str2 >> p;
            ans.insert(pair < string , int > (variable[0],p));
            res = p;
        }else{
            ans.insert(pair < string , int > (variable[0],ans.find(variable[2])->second));
            res = ans.find(variable[2])->second;
        }
    }else{
       ans.insert(pair < string , int > (variable[0],(ans.find(variable[2])->second) + ans.find(variable[4])->second));
       res = ans.find(variable[2])->second + ans.find(variable[4])->second ;
      }
    }
    cout << res << endl;
    return 0;
}

Thursday, April 6, 2017

Uri 2344 - Notas da Prova

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin >> n;
    cout << ((n == 0)? 'E' : (n < 36)? 'D' : (n < 61)? 'C' : (n < 86)? 'B' : 'A') << endl;
    return 0;
}

Uri 1147 - Knight Scape

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

int d_x[] = {1,1,2,2,-1,-1,-2,-2},
    d_y[] = {2,-2,1,-1,2,-2,1,-1};

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int idx = 0,n;
    char ch;
    while(cin >> n >> ch and n ){
        int res = 0;
        vector < vector < int> > ans(8, vector(8));
        int x = n - 1,
            y = ch - 'a';
        for(int i = 0; i < 8 ; i++){
            cin >>  n >> ch;
            ans[n - 1][ch - 'a'] = 1;
        }

        for(int i = 0; i < 8 ; i++){
                int x1 = x + d_x[i],
                    y1 = y + d_y[i];
        if(x1 >= 0 and x1 < 8 and y1 >= 0 and y1 < 8){
            int x2 = x1 + 1,
                y2 = y1 - 1,
                k = 1;

            if(x2 >= 0 and x2 < 8 and y2 >= 0 and y2 < 8 and ans[x2][y2]) k = 0;
            y2 = y1 + 1;
            if(x2 >= 0 and x2 < 8 and y2 >= 0 and y2 < 8 and ans[x2][y2]) k = 0;
            if(k) res++;
        }
    }
        cout << "Caso de Teste #" << ++idx << ": " << res << " movimento(s)." << endl;
    }
    return 0;
}

Uri 1403 - Grandpa is Famous


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

template
struct less_second {
    typedef pair < T1, T2 > type;
    bool operator ()(type const& a, type const& b) const {
        if(a.second != b.second)
        return a.second > b.second;

        return a.first < b.first;
    }
};

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,m,p = 0;
    int t;
    while(cin >> n >> m and (n+m) != 0){
    int k = 0 , p = 0;
    map < int , int > ans;
    for(int i = 0; i < n*m ; i++){
          cin >> t;
          ans[t]++;
     }

     vector < pair < int, int > > ans1(ans.begin(), ans.end());
     sort(ans1.begin(), ans1.end(), less_second < int, int >());
     vector < pair < int, int > > :: iterator it = ans1.begin();
     it++;

     for(;it != ans1.end() ; it++,p = 1){
             if(k == 0) k = it->second ;
             if( k == (it->second)){
             cout << it->first << " " ;
             }else{
                break;
             }
        }
         cout << endl;
    }
    return 0;
}

Uri 1936 - Factorial

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

int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
    int ar[10] = {0,1,2,6,24,120,720,5040,40320,362880};
    int n,c = 0,i,n1 = 0,l1;
    cin >> n;
    l1 = n;
    while(l1!=0){
        for(i = 1;  ; i++) if(ar[i] >= l1 or i > 8) break;
         (ar[i] <= l1)? l1 -= ar[i] : l1 -= ar[i-1];
          c++;
    }
    cout << c << endl;
    return 0;
}

Wednesday, April 5, 2017

Uri 1800 - Where Are My Keys

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int week_office,two_days_office,k;
    cin >> week_office >> two_days_office;

    set < int > two_days_office_s;

    for(int i = 0; i < two_days_office ;i++){
         cin >> k;
         two_days_office_s.insert(k);
    }

    while(week_office--){
        cin >> k;
        cout << ((two_days_office_s.count(k))? 0 : 1 ) << endl;
        two_days_office_s.insert(k);
    }

    return 0;
}



Tuesday, April 4, 2017

Uri 1895 - Game of Limit

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,c,t_i,l,Ali=0,Bo=0,c_b;
    cin >> c >> t_i >> l;
    for(int i = 0; i < c-1 ; i++){
        cin >> c_b;
        n = abs(c_b - t_i);
        if(n <= l){
            (i&1)? Bo += n : Ali += n;
            t_i = c_b;
        }
    }
    cout << Ali << " " << Bo << endl;
    return 0;
}

Uri 2134 - Who Will Fail?

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

struct mode{
    string name;
    int problem_num;
}recod[1001];

bool cmp(const mode &a, const mode &b){
    if(a.problem_num != b.problem_num)
        return a.problem_num < b.problem_num ;
    return a.name > b.name;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,case_n = 0,t = 0;
    while(cin >> n){
            if(t != 0) cout << endl;
    for(int i = 0; i < n ;i++){
        cin >> recod[i].name >> recod[i].problem_num;
    }
    stable_sort(recod,recod+n,cmp);
    cout << "Instancia " << ++case_n << endl << recod[0].name << endl;
    for(int i = 0; i < n ;i++)
       recod[i].name.clear(),recod[i].problem_num = 0;
    t=1;
    }
    cout << endl;
    return 0;
}

Uri 1845 - Efilogue


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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    char ch;
    bool check;
    set < char > sd,sd1;
    sd.insert('J');sd1.insert('j');sd.insert('B');sd1.insert('b');
    sd.insert('V');sd1.insert('v');sd.insert('Z');sd1.insert('z');
    sd.insert('S');sd1.insert('s');sd.insert('P');sd1.insert('p');
    sd.insert('X');sd1.insert('x');
    while((ch = getchar()) != EOF)
    {
        if(sd.count(ch) != 0) ch = 'F';
        else if(sd1.count(ch) != 0)ch = 'f';

        if(!((ch == 'f' or ch == 'F') and check))cout << ch;
        if(ch == 'f' or ch == 'F')check = true;
        else check = false;
    }
    return 0;
}

Uri 1898 - Kickback Sum


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

int c = 0,cr = 0;

string add_big_double_value(string fr,string se,int carry){

    string res="",check1 = "",check2 = "";

    int fr_l = fr.size(),
        se_l = se.size();

    if(fr_l < se_l) swap(fr,se);
            int len = fr.size(),
                se_len = se.size();

    if(cr)reverse(se.begin(),se.end());
    for(int i = se_len ; i < len ; i++) se += '0';
    if(cr)reverse(se.begin(),se.end());
    int digit = 0; c = carry;

    for(int i = len-1 ; i >= 0 ; i--){
            digit = (fr[i] - '0') + (se[i] - '0') + c;
            res += (digit > 9)? (digit - 10) + '0' : digit + '0' ;
            (digit > 9)? c = 1 : c = 0;
    }
    cr = 1;
    reverse(res.begin(),res.end());
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long cpf_n;
    long poi;
    int p1 = 0,p2 = 0,p = 0;
    bool b = false;
    string s,s1,input1="",input2="",cpf,se_res,point_str1 = "" ,point_str2 = "",dec_str;
    cin >> s >> s1;
    for(int i = 0; i < s.size() ;i++){
        if(((s[i] >= '0' and s[i] <= '9') or s[i] == '.') and cpf.size() < 11){
            if(b and s[i] == '.') {
                    cpf += s[i];
                    break;
            }
            cpf += s[i];
            if(b) p++;
            if(p>=2) {
                if(cpf.size() < 11) return cout << "cpf " << cpf << endl , 0;
                break;
            }
            if(s[i] == '.'){
                b = true;
            }
        }else if(((s[i] >= '0' and s[i] <= '9') or s[i] == '.') and cpf.size() >= 11){
                    if(b and s[i] == '.') break;
                    if(p >= 2)break;
                    if(b) p++;
                    (b)?(input1.size() < 2)? input1 += s[i] : point_str1 += s[i] : (s[i] != '.')? input1 += s[i] : input1 = input1;
                    if(s[i] == '.') b = true;
                }
            }

     b = false;
     p = 0;

    for(int i = 0; i < s1.size() ;i++){
       if((s1[i] >= '0' and s1[i] <= '9') or s1[i] == '.'){
                     if(b and s1[i] == '.') break;

                    (b)? point_str2 += s1[i] : (s1[i] != '.')? input2 += s1[i] : input2 = input2;

                    if(b) p++;
                    if(p >= 2)break;
                    if(s1[i] == '.') b = true;
                    }
    }
    if(point_str1.empty()) point_str1 = "00";if(point_str2.empty()) point_str2 = "00";
    se_res = add_big_double_value(point_str1,point_str2,c);
    dec_str = add_big_double_value(input1,input2,c);
    if(c) dec_str += '1';

    cout << "cpf " << cpf << endl << dec_str  <<   "."  << se_res << endl;
    return 0;
}

Monday, April 3, 2017

Uri 1868 - Square Spiral

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

int x_dr[] = {0,-1,0,1};
int y_dr[] = {1,0,-1,0};
int x,y;

void show_result(vector < vector < char > > &ch){
  for (int i = 0; i < ch.size(); i++) {
    for (int j = 0; j < ch.size(); j++) {
      cout << ch[i][j];
    }
    cout << endl;
  }
  cout << "@" << endl;
}

bool moving(vector < vector < char > > &ch,int item,int d){
    int n = ch.size();
    for(int i = 0; i < item ;i++){
        int new_x = x + x_dr[d],new_y = y + y_dr[d];

        if(new_x < 0 or new_x >= n or new_y < 0 or new_y >= n) return false;

        ch[x][y] = 'O';
        x = new_x ,y = new_y;
        ch[x][y] = 'X';
        show_result(ch);
    }
 return true;
}

int main()
{
    int n;
    while(cin >> n and n != 0){
        vector < vector < char > > ch(n,vector < char > (n, 'O'));
        int item = 0;
        x = n >> 1;
        y = n >> 1;
        ch[x][y] = 'X';
        show_result(ch);
        while(true){
            item++;
        if(!moving(ch,item,0)) break;
        if(!moving(ch,item,1)) break;
        item++;
        if(!moving(ch,item,2)) break;
        if(!moving(ch,item,3)) break;
        }
    }
    return 0;
}

Sunday, April 2, 2017

Uri 1254 - Tag Replacement

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

int main()
{
    string s,s1;
    while(cin >> s >> s1){
            cin.ignore();
        set < char > let;

        bool b = false;
        string input,word,word1;

        getline(cin,input);
        transform(s.begin(),s.end(),s.begin(), ::tolower);

        for(int i = 0; i < s.size() ;i++) let.insert(s[i]);

        for(int i = 0; i < input.size() ;i++){
            if(isalpha(input[i]) or (input[i] >= '0' and input[i] <= '9')){

             word += input[i];
             word1 = word;
             transform(word1.begin(),word1.end(),word1.begin(), ::tolower);

                if(word1 == s and b){
                cout << s1;
                word.clear();
                word1.clear();
                 }

                if(word.size() == 1){
                    if(let.count(tolower(input[i])) == 0) {
                        cout << input[i];
                        word1.clear();
                        word.clear();
                    }
                 }
            }else if(input[i] == ' ' and word1 == s and b){
                     cout << s1 << " ";
                     word.clear();
            }else if(input[i] == '>' and word1 == s and b){
                     cout << s1 << ">";
                     word.clear();
                     b = false;
            }else if(input[i] == '<'){
                     b = true;
                     (word.empty())? cout << '<' : cout << word << "<";
                     word.clear();
            }else if(input[i] == '>'){
                     (word.empty())?cout << '>' : cout << word << ">";
                     word.clear();
                     b = false;
                }else {
                    (word.empty())? cout << input[i] : cout << word << input[i];
                     word.clear();
            }
        }
        if(!word.empty()) cout << word << endl;
        else cout << endl;
    }
    return 0;
}

Uri 2523 - Will's Message

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

int main()
{
    char s[1001];
    int n,l;
    while(scanf("%s",s) != EOF){
        scanf("%d",&n);
        while(n--){
                scanf("%d",&l);
            printf("%c",s[l-1]);
        }
        printf("\n");
    }
    return 0;
}

Uri 2502 - Deciphering the Encrypted Card

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

int main()
{
    int n,m;
    string orginal_input,result;
    string s1,s2;
    while(cin >> n >> m){
          multimap < char , int > st1,st2;
          cin.ignore();
          getline(cin,s1);
          getline(cin,s2);
          for(int j = 0 ; j < n ;j++){
            st1.insert(pair < char , int >(s1[j],j));
            st2.insert(pair < char , int >(s2[j],j));
          }
        int index ;
        while(m--){
            getline(cin,orginal_input);
            for(int i = 0;  i < orginal_input.size() ; i++){
                    char ch = toupper(orginal_input[i]);
                if(st1.count(ch) == 0 && st2.count(ch) == 0){
                        result += orginal_input[i];
                }else if(st1.count(ch) != 0){
                    index = st1.find(ch)->second;
                    result += !isupper(orginal_input[i]) ? (char) tolower(s2[index]) : s2[index];
                }else if(st2.count(ch) != 0){
                    index = st2.find(ch)->second;
                    result += !isupper(orginal_input[i]) ? (char) tolower(s1[index]) : s1[index];
                }
            }
            cout << result << endl;
            result.clear();
        }
        cout << endl;
    }

    return 0;
}

Saturday, April 1, 2017

Uri 2520 - The Last Analógimôn

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

int main()
{
    int n,m,a,b,c,r;
    while(scanf("%d %d",&n,&m) != EOF){
       int ans[101][101];
     for(int i = 0;  i < n ;i++){
       for(int j = 0; j < m ;j++){
        scanf("%d",&ans[i][j]);
        if(ans[i][j] == 1) a = i,b = j;
        if(ans[i][j] == 2) r = i, c = j;
       }
     }
       int res = 0;
       res = abs(c - b) + abs(r - a);
       printf("%d\n",res);
    }
    return 0;
}

Uri 1276 - Letter Range

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

int main()
{
    int ans[27];
    string s;
    while(getline(cin,s)){
        memset(ans,0,sizeof(ans));
        set < char > res;
        int p = 0;
        for(int i = 0; i < s.size() ;i++){
            ans[s[i] - 'a'] = 1;
            res.insert(s[i]);
        }
        char ch = '#';
        for(int i = 0; i < 26 ;i++){
            if(ans[i]){
                if(ch == '#') ch = (char)(i+'a');
            }else{
                if(res.count(ch) != 0){
                    if((ch - 'a') - i == 1)
                         (p)? cout << ", " << ch << ":" << ch : cout << ch << ":" << ch;
                    else
                         (p)? cout << ", " << ch << ":" << (char) ((i-1)+'a') : cout << ch << ":" << (char)((i-1)+'a') ;
                p=1;
                }
                ch = '#';
            }
        }
        if(ch != '#')(p)?cout << ", " << ch << ":" << 'z' :cout << ch << ":" << 'z' ;
        cout << endl;
    }
    return 0;
}

Sunday, March 26, 2017

Uri 2508 - Fortune Teller

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

int return_value(char ch){
   if(ch == 'A' or ch == 'J' or ch == 'S') return 1;
   else if(ch == 'B' or ch == 'K' or ch == 'T') return 2;
   else if(ch == 'C' or ch == 'L' or ch == 'U') return 3;
   else if(ch == 'D' or ch == 'M' or ch == 'V') return 4;
   else if(ch == 'E' or ch == 'N' or ch == 'W') return 5;
   else if(ch == 'F' or ch == 'O' or ch == 'X') return 6;
   else if(ch == 'G' or ch == 'P' or ch == 'Y') return 7;
   else if(ch == 'H' or ch == 'Q' or ch == 'Z') return 8;
   else if(ch == 'I' or ch == 'R') return 9;
}
int single_digit(int n){
   int t = 0;
    while(n != 0){
        t += n % 10;
        n /= 10;
        }
   return t;
}
int main()
{
   // freopen("in.txt","r",stdin);
    string s;
    while(getline(cin,s)){
        transform(s.begin(), s.end(),s.begin(), ::toupper);
        int sum = 0;
        for(int i = 0 ;i < s.size() ; i++ ) {
            if(s[i] != 32)
            sum += return_value(s[i]);
        }
        while(sum > 9){
            sum = single_digit(sum);
        }
         cout << sum << endl;
    }

    return 0;
}

Uri 2496 - The Only Chance

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

int main()
{
    //freopen("in.txt","r",stdin);
    int n,t,l;
    string s;
    string orginal_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cin >> n;
    while(n--){
        bool b = true;
        int p = 0;
        cin >> t;
        cin >> s;
        for(int i = 0; i < t; i++){
            if(s[i] != orginal_string[i]){
               if(orginal_string[i] != s[((int)(s[i]) - 65)] or p > 0){
                     b = false;
                     break;
               }else{
                   swap(s[i],s[((int)(s[i]) - 65)]);
                   p++;
               }
            }
        }
     cout << ((b == true and p < 2) ?  "There are the chance.\n" : "There aren't the chance.\n");
    }
    return 0;
}

Uri 2495 - Where is my Pen?

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

int main()
{
    //freopen("in.txt","r",stdin);
    int n,k,l,res = 0;
     while(cin >> n){
        int ans[100010];
        memset(ans,0,sizeof ans);
        l = n;
        n--;
        while(n--){
            cin >> k;
            ans[k] = 1;
        }
        for(int i = 1 ; i <= l ;i++){
            if(ans[i] == 0) {
                res = i ;
                break;
            }
        }
        cout << res << endl;
     }
    return 0;
}

Uri 2290 - Apaixornados Numbers

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

int main()
{
    //freopen("in.txt","r",stdin);
    long long ar[100010];
    int n;
    while(cin  >> n and n != 0){
        memset(ar,0,sizeof ar);
            int t = 0;
        for(int i = 0;i < n ; i++) cin >> ar[i];

        sort(ar,ar+n);
        for(int i= 0 ; i < n and t < 2 ;){
             if(ar[i] == ar[i+1] and i < n-1){
                i += 2;
             }else{
                 cout << ar[i];
                 cout << ((t == 1) ?  "\n" : " ") ;
                 i++;
                 t++;
             }
        }
    }
    return 0;
}

Uri 1861 - Hall of Murderers

#include <bits/stdc++.h>

using namespace std;

 int main()
 {
     int t = 0;
     string name1, name2;
     multimap < string , int> criminal,vectim;
     map < string ,int > ans;
     while(cin >> name1 >> name2){
         criminal.insert(pair(name1,0));
         vectim.insert(pair(name2,0));
     }
     for(multimap < string , int > :: iterator it = criminal.begin(); it != criminal.end(); it++){
         string as = it->first;
         int t = 1;
        if(vectim.count(as) == 0){
            ans[as]++;
        }
     }

     cout << "HALL OF MURDERERS" << endl;
         for(map < string , int > ::iterator it2 = ans.begin(); it2 != ans.end();it2++){
         cout << it2->first << " " << it2->second << endl;
     }
     return 0;
 }

Uri 2510 - Batmain

#include <bits/stdc++.h>  


 using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  while(n--) {
      cin >> s;
      cout << ((s != "Batman") ?  "Y" : "N") << endl;
  }

    return 0;
}

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