UIU Competitive Programmers contest – 04 Solutions


All solutions written by: Rimon Mostafiz

A-Odd Sum


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    int test, Case = 0;
    cin >> test;
    while(test--) {
        int l, r, odd_sum = 0;
        cin >> l >> r;
        for(int i=l; i<=r; i++) {
            if(i%2) odd_sum += i;
        }

        cout << "Case " << ++Case << ": " << odd_sum << endl;
    }
    return 0;
}

B-One-Two-Three


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    int test;
    cin >> test;
    while(test--) {
        string st;
        cin >> st;
        if(st.size()==5) cout << 3 << endl;
        else {
            int cnt = 0;
            if(st[0]=='o') cnt++;
            if(st[1]=='n') cnt++;
            if(st[2]=='e') cnt++;

            if(cnt>=2) cout << 1 << endl;
            else cout << 2 << endl;
        }
    }
    return 0;
}

C-Nasty Hacks


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    int test;
    cin >> test;
    while(test--) {
        int r, e, c;
        cin >> r >> e >> c;
            if(e-c < r) cout << "do not advertise" << endl;
            else if(e-c > r) cout << "advertise" << endl;
            else cout << "does not matter" << endl;
        }
    return 0;
}

D-Misspelling


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    int test, Case = 0;
    cin >> test;
    while(test--) {
        int n;
        string st;
        cin >> n >> st;
        st.erase(st.begin() + n-1);
        cout << ++Case<< " " <<st << endl;
    }
    return 0;
}

E-Summing Digits


#include <cstdio>
#include <iostream>

using namespace std;

int recur (int n) {
    if(n<10) return n;
    int ret = 0;
    while(n) {
        ret += n % 10;
        n /= 10;
    }
    return recur(ret);
}

int main() {
    ios_base::sync_with_stdio(0);
    int n;
    while(cin >> n && n) {
        cout << recur(n) << endl;
    }
    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s