Showing posts with label Stl-vector. Show all posts
Showing posts with label Stl-vector. Show all posts

Sunday, September 15, 2019

Uri 1495 - Football

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

vector< int > v;

bool compare(int a, int b) { return (a > b); }

int main(int argc, char const *argv[])
{
int n, g, s, r, c, i, sz;
bool b;

while(scanf("%d %d", &n, &g) == 2)
{
c = 0;
v.clear();

for (i = 0; i < n; ++i)
{
scanf("%d %d", &s, &r);
if(s > r) c += 3;
else v.push_back(s - r);
}

sort(v.begin(), v.end(), compare);
sz = v.size();
b = false;

for (i = 0; i < sz; ++i)
{
if(b){
if(v[i] == 0) c++;
else break;
}else{
if(g <= 0) b = true;

if((1 - v[i]) <= g){
g -= (1 - v[i]);
c += 3;
}else if((0 - v[i]) == g){
c++;
g -= (0-v[i]);
}else{
b = true;
}
}
}

printf("%d\n", c);
}

return 0;
}

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

Sunday, April 9, 2017

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