Tuesday, September 19, 2017

Uri 2338 - Morse

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

int main()
{
    map < string , char > data;
    data["=.==="]        = 'a';
    data["===.=.=.="]    = 'b';
    data["===.=.===.="]    = 'c';
    data["===.=.="]        = 'd';
    data["="]        = 'e';
    data["=.=.===.="]    = 'f';
    data["===.===.="]        = 'g';
    data["=.=.=.="]    = 'h';
    data["=.="]        = 'i';
    data["=.===.===.==="]    = 'j';
    data["===.=.==="]        = 'k';
    data["=.===.=.="]    = 'l';
    data["===.==="]        = 'm';
    data["===.="]        = 'n';
    data["===.===.==="]        = 'o';
    data["=.===.===.="]    = 'p';
    data["===.===.=.==="]    = 'q';
    data["=.===.="]        = 'r';
    data["=.=.="]     = 's';
    data["==="]        = 't';
    data["=.=.==="]        = 'u';
    data["=.=.=.==="]    = 'v';
    data["=.===.==="]        = 'w';
    data["===.=.=.==="]    = 'x';
    data["===.=.===.==="]    = 'y';
    data["===.===.=.="]    = 'z';
    data["===.===.===.===.==="]    = '0';
    data["=.===.===.===.==="]    = '1';
    data["=.=.===.===.==="]    = '2';
    data["=.=.=.===.==="]    = '3';
    data["=.=.=.=.==="]    = '4';
    data["=.=.=.=.="]    = '5';
    data["===.=.=.=.="]    = '6';
    data["===.===.=.=.="]    = '7';
    data["===.===.===.=.="]    = '8';
    data["===.===.===.===.="]    = '9';
    data["=.===.=.===.=.==="]  = '.';
    data["===.===.=.=.===.==="]  = ',';
    data["=.=.===.===.=.="]  = '?';
    data["=.===.===.===.===.="]  = '\'';
    data["===.=.===.=.===.==="]  = '!';
    data["===.=.=.===.="]    = '/';
    data["===.=.===.===.="]    = '(';
    data["===.=.===.===.=.==="]  = ')';
    data["=.===.=.=.="]    = '&';
    data["===.===.===.=.=.="]  = ':';
    data["===.=.===.=.===.="]  = ';';
    data["===.=.=.=.==="]    = '=';
    data["=.===.=.===.="]    = '+';
    data["===.=.=.=.=.==="]  = '-';
    data["=.=.===.===.=.==="]  = '_';
    data["=.===.=.=.===.="]  = '"';
    data["=.===.===.=.===.="]  = '@';
    string line;
    int n,tc = 0;
    cin  >>  n;
    getline(cin,line);
    while(n--){
        if(tc != 0) cout << endl;
        int dot = 0;
        getline(cin,line);
        string text;
        for(int i = 0;  i < line.size() ; i++ ){
            if(line[i] == '.') dot++;
            else{
                if(dot == 3) text += " ";
                else if(dot == 7)  text += "  ";
                else if(dot == 1) text += '.';
                text +=  line[i];
                dot = 0;
            }
        }
        line  = text;
        stringstream word;
        word << line;

        while(word >> line){
            cout << data[line];

            if(word.good()){
                char ch = word.get();
                     ch = word.peek();
                 if(ch == ' ' ) cout << " " ;
            }
        }
        cout << endl;
    }

    return 0;
}

Monday, September 18, 2017

Donald Knuth Biography :

Donald Knuth Biography :

Born: 10 January 1938 in Milwaukee, Wisconsin, USA




 

Saturday, May 6, 2017

Uri 1667 - HTML


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
string s;
char ch;
while(scanf("%c",&ch)!=EOF){
s+=ch;
}
stringstream str1(s);
vector < string > variable;
string take;
while (str1 >> take)
variable.push_back(take);
int len = 0;
string sd;
for(int i = 0; i < variable.size() ; i++){
bool b = true;
sd = variable[i];
string st = (i != 0)? variable[i - 1] : sd ;
if(len+sd.size() > 80 and sd != "< br >" and sd[sd.size()-1] != '.') {
cout << endl, len = 0;
}else if(len+sd.size()+1 > 80 and sd != "< br >" and sd[sd.size()-1] == '.'){
cout << endl, len = 0;
}
if(st[st.size()-1] == '.' and len > 75 and sd != "< br >"){
cout << endl, len = 0;
}
if(variable[i] == "< br >"){
cout << endl;
len = 0,b=false;
}
else if(variable[i] == "< hr >")
if(len!=0) cout << endl << "--------------------------------------------------------------------------------\n", len = 0,b = false;
else cout << "--------------------------------------------------------------------------------\n",len = 0,b=false;
else (i == 0 or len == 0)? cout << variable[i] : cout << " " << variable[i] ;
if(b) len += sd.size()+1;
}
if(sd != "< br >")cout << endl;
return 0;
}

Monday, April 10, 2017

Uri 2248 - Internship

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

struct ans{
    int a = 0;
    int b = 0;
}rec[1511];

bool cmp(const ans &x, const ans &y){
    return x.b > y.b;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
     int n ,m,k,l,ca = 0;

     while(cin >> k and k){
          for(int i = 0; i < k ;i++){
            cin >> rec[i].a >> rec[i].b;
          }
          stable_sort(rec,rec+k,cmp);

     cout << "Turma " << ++ca << endl;

       bool b = true;

     for( int i = 1 ;i < k ; i++){
            if(b) cout << rec[i-1].a << " " ;

            if(rec[i].b != rec[i-1].b and b) {
                cout << endl ;
                    b = false;
             }
             rec[i-1].a = 0, rec[i-1].b = 0;
      }

      if(b) cout << rec[k-1].a << " " << endl;
      rec[k].a = 0, rec[k].b = 0;

      cout << endl ;
     }
    return 0;
}

Sunday, April 9, 2017

Uri 1652 - Deli Deli

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

int main(){
    string s,s1;
    int n,k;
    cin >> n >> k;
    map < string , string > ans;
    while(n--){
        cin >> s >> s1;
        ans.insert(pair < string , string > (s,s1));
            }
            while(k--){
                cin >> s;
                s1 = s;
                if(ans.count(s) != 0)
                    cout << ans.find(s)->second << endl;
                else{
                    if(s[s.size()-1] == 'y' and (s[s.size()-2] != 'a' and s[s.size()-2] != 'e' and s[s.size()-2] != 'i' and s[s.size()-2] != 'o' and  s[s.size()-2] != 'u'))
                        s[s.size()-1] = 'i',s +="es";
                    else if(s[s.size()-1] == 'o' or (s[s.size()-1] == 's') or (s[s.size()-2] == 'c' and (s[s.size()-1] == 'h')) or (s[s.size()-2] == 's' and s[s.size()-1] == 'h') or (s[s.size()-1] == 'x'))
                        s += "es";
                    else
                        s += "s";
                    cout << s << endl;
                    ans.insert(pair(s1,s));
                }
            }
    return 0;
}

Uri 1832 - EBCDIC

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

int octal_to_decimal(int oc){
  int d = 0, i = 0, rem;
    while (oc != 0)
    {
        rem = oc % 10;
        oc /= 10;
        d += rem * pow(8, i);
        ++i;
    }
    return d;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long n,k = 0;
    string s;
        int Tableebc2Asc[256] =
    {
            32,  32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 91, 46, 60, 40, 43, 33,
            38, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 93, 36, 42, 41, 59, 94,
            45, 47, 32, 32, 32, 32, 32, 32,
            32, 32,124, 44, 37, 95, 62, 63,
            32, 32, 32, 32, 32, 32,238,160,
            161, 96, 58, 35, 64, 39, 61, 34,
            230, 97, 98, 99,100,101,102,103,
            104,105,164,165,228,163,229,168,
            169,106,107,108,109,110,111,112,
            113,114,170,171,172,173,174,175,
            239,126,115,116,117,118,119,120,
            121,122,224,225,226,227,166,162,
            236,235,167,232,237,233,231,234,
            158,128,129,150,132,133,148,131,
            123, 65, 66, 67, 68, 69, 70, 71,
            72, 73,149,136,137,138,139,140,
            125, 74, 75, 76, 77, 78, 79, 80,
            81, 82,141,142,143,159,144,145,
            92, 32, 83, 84, 85, 86, 87, 88,
            89, 90,146,147,134,130,156,155,
            48, 49, 50, 51, 52, 53, 54, 55,
            56, 57,135,152,157,153,151, 32
    };
    while(getline(cin,s)){
            vector < string > ans;
            stringstream stl(s);
            string take;
            while (stl >> take)
            ans.push_back(take);

            for(int i = 0 ; i < ans.size() ; i++){
            stringstream str2(ans[i]);
            int p = 0;
            str2 >> p;
            unsigned char d = octal_to_decimal(p);
            (i != ans.size()-1)?printf("%c",Tableebc2Asc[d]) : printf("%c\n",Tableebc2Asc[d]);
            }
    }
    return 0;
}

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