Sunday, 27 November 2016

11150 - Cola Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    int n;
    while(cin >> n)cout << n+(n/2) << endl;
    return 0;
}

10420 - List of Conquests Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    string str,s;
    int n;
    cin >> n;
    map<string,int>m;
    map<string,int>::iterator i;
    for(int i = 0; i < n; i++){
        cin >> s;getline(cin,str);
        m[s]++;
    }
    for(i = m.begin(); i != m.end(); i++)cout << i->first << " " << i->second << endl;
    return 0;
}

10921 - Find the Telephone Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    string str;
    while(cin >> str){
        int len = str.length();
        string s = "";
        for(int i = 0; i < len; i++){
            if(str[i] == 'A' || str[i] == 'B' || str[i] == 'C')s += "2";
            else if(str[i] == 'D' || str[i] == 'E' || str[i] == 'F')s += "3";
            else if(str[i] == 'G' || str[i] == 'H' || str[i] == 'I')s += "4";
            else if(str[i] == 'J' || str[i] == 'K' || str[i] == 'L')s += "5";
            else if(str[i] == 'M' || str[i] == 'N' || str[i] == 'O')s += "6";
            else if(str[i] == 'P' || str[i] == 'Q' || str[i] == 'R' || str[i] == 'S')s += "7";
            else if(str[i] == 'T' || str[i] == 'U' || str[i] == 'V')s += "8";
            else if(str[i] == 'W' || str[i] == 'X' || str[i] == 'Y' || str[i] == 'Z')s += "9";
            else s += str[i];
        }
        cout << s << endl;
    }
    return 0;
}

483 - Word Scramble Uva Problem Solution


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    string str;
    while(getline(cin,str)){
        int len = str.length();
        vector<string>tmp;
        string s = "";
        for(int i = 0; i < len; i++){
            if(str[i] != ' ')s += str[i];
            else {
                reverse(s.begin(),s.end());
                tmp.push_back(s);
                s.clear();
            }
        }
        reverse(s.begin(),s.end());
        tmp.push_back(s);
        int sz = tmp.size();
        for(int i = 0; i < sz; i++){
            cout << tmp[i];
            if(i != sz-1)cout << " ";
        }
        cout << endl;
        str.clear();
    }
    return 0;
}

Saturday, 26 November 2016

12554 - A Special "Happy Birthday" Song!!! Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
int main(){

    int n;
    string song[] = {"Happy","birthday","to","you","Happy","birthday",
                    "to","you","Happy","birthday","to","Rujia","Happy","birthday","to","you"};
    string names[105];
    cin >> n;
    for(int i = 0; i < n; i++)cin >> names[i];
    int loop = 0;
    if(n <= 16)loop = 1;
    else if(n <= 32)loop = 2;
    else if(n <= 48)loop = 3;
    else if(n <= 64)loop = 4;
    else if(n <= 80)loop = 5;
    else if(n <= 96)loop = 6;
    else loop = 7;
    for(int i = 0, j = 0,k = 0; i < 16*loop; i++){
        cout << names[j++] << ": " << song[k++] << endl;
        if(j == n)j = 0;
        if(k == 16)k = 0;
    }
    return 0;
}

12015 - Google is Feeling Lucky Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
struct Web{
    string url;
    int rel;
};
int main(){
    int T;
    cin >> T;
    for(int t = 1; t <= T; t++){
        Web pages[100];
        int rel,mxRel = -1;
        for(int i = 0; i < 10; i++){
            cin >> pages[i].url >> pages[i].rel;
            if(pages[i].rel > mxRel)mxRel = pages[i].rel;
        }
        cout << "Case #"<< t << ":" << endl;
        for(int i = 0; i < 10; i++)if(pages[i].rel == mxRel)cout << pages[i].url << endl;
    }
    return 0;
}

11799 - Horror Dash Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
int main(){

    int n,T;
    cin >> T;
    for(int t = 1; t <= T; t++){
        cin >> n;
        int mxS = -1,a;
        for(int i = 0; i < n; i++){
            cin >> a;
            if(a > mxS)mxS = a;
        }
        cout << "Case " << t << ": " << mxS << endl;
    }
    return 0;
}

12503 - Robot Instructions Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
int main(){
    int T,n;
    string query[105];
    cin >> T;
    for(int t = 0; t < T; t++){
        cin >> n;
        string str1,str2;
        int str3,p = 0;
        for(int i = 1; i <= n; i++){
            cin >> str1;
            if(str1 == "LEFT"){
                query[i] = str1;
                p--;
            }
            else if(str1 == "RIGHT"){
                query[i] = str1;
                p++;
            }
            else{
                cin >> str2 >> str3;
                query[i] = query[str3];
                if(query[str3] == "LEFT")p--;
                else if(query[str3] == "RIGHT")p++;
            }
        }
        cout << p << endl;
    }
    return 0;
}

1124 - Celebrity jeopardy Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
int main(){
    string s;
    while(getline(cin,s))cout << s << endl;
    return 0;
}

10300 - Ecological Premium Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
 *
 * Prosen Ghosh
 * American International University - Bangladesh (AIUB)
 *
*/
int main(){

    int T,n;
    cin >> T;
    for(int t = 0; t < T; t++){
        cin >> n;
        int sum = 0,a,b,c;
        for(int i = 0; i < n; i++){
            cin >> a >> b >> c;
            sum += a*c;
        }
        cout << sum << endl;
    }
    return 0;
}

Thursday, 24 November 2016

Designer PDF Viewer Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    int height = -1,len,heights[26];
    string str;
    for(int i = 0; i < 26; i++)cin >> heights[i];
    cin >> str;
    len = str.length();
    for(int i = 0; i < len; i++){
        if(heights[str[i]-'a'] > height)height = heights[str[i]-'a'];
    }
    cout << len*height << endl;
    return 0;
}

Sunday, 20 November 2016

12289 - One-Two-Three Uva Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){ int T; string one = "one"; cin >> T; for(int t = 0; t < T; t++){ string str; cin >> str; if(str.length() == 5)cout << 3 << endl; else { int cnt = 0; for(int i = 0; i < 3; i++)if(str[i] == one[i])cnt++; (cnt >= 2) ? cout << 1 << endl : cout << 2 << endl; } } return 0; }

Saturday, 19 November 2016

12403 - Save Setu Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int tmpVal;
string cutStr(string str){
    int len = str.length();
    string tmpStr = "";
    tmpVal = 0;
    for(int i = 0; i < len; i++){
        if(str[i] >= 'a' && str[i] <= 'z')tmpStr+=str[i];
        else if(str[i] >= '0' && str[i] <= '9')tmpVal = tmpVal * 10 + (str[i] - '0');
    }
    return tmpStr;
}
int main() {
    int T,blance = 0;
    cin >> T;cin.ignore();
    for(int t = 1; t <= T; t++){
        string str;
        getline (cin,str);
        if(cutStr(str) == "donate")blance += tmpVal;
        else if(cutStr(str) == "report")cout << blance << endl;
    }
    return 0;
}

11764 - Jumping Mario Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() { int T; cin >> T; for(int t = 1; t <= T; t++){ int l = 0,h = 0,n,a,checker = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> a; if(i == 0)checker = a; else{ if(a > checker){ h++; checker = a; } else if(a < checker){ l++; checker = a; } } } cout << "Case " << t << ": " << h << " " << l << endl; } return 0; }

Friday, 18 November 2016

12577 - Hajj-e-Akbar Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    string str;
    int i = 0;
    while(cin >> str && str != "*"){
        if("Hajj" == str)cout << "Case " << ++i << ": " <<  "Hajj-e-Akbar" << endl;
        else if("Umrah" == str)cout << "Case " << ++i << ": " <<  "Hajj-e-Asghar" << endl;
    }
    return 0;
}

11547 - Automatic Answer Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    int T,n;
    cin >> T;
    for(int t = 0; t< T; t++){
        cin >> n;
        int res,eq = (((((n*567)/9)+7492)*235)/47)-498;
        eq /= 10;
        res = eq %10;
        cout << abs(res) << endl;
    }
    return 0;
}

11364 - Parking Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    int T;
    cin >> T;
    for(int t = 0; t< T; t++){
        int n;cin >> n;
        vector<int>ar;
        for(int i = 0; i < n; i++){
            int a;cin >> a;
            ar.push_back(a);
        }
        sort(ar.begin(),ar.end());
        int sum = 0;
        for(int i = 0; i < n-1; i++)sum += abs(ar[i]-ar[i+1]);
        cout << sum+abs(ar[0]-ar[n-1]) << endl;
    }
    return 0;
}

591 - Box of Bricks Uva Problem SOlution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    int n,_set = 0;
    while(cin >> n && n != 0){
        vector<int>ar;
        int sum = 0;
        for(int i = 0; i < n; i++){
            int a;cin >> a;
            sum += a;
            ar.push_back(a);
        }
        int chk = sum/n,cnt = 0;
        for(int i = 0; i < n; i++){
            if(ar[i] > chk)cnt+= ar[i]-chk;
        }
        cout << "Set #" << ++_set << endl;
        cout << "The minimum number of moves is " << cnt << "." << endl << endl;
        
    }
    return 0;
}

10055 - Hashmat the Brave Warrior Uva Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
#define print(a,b) cout << abs(a-b) << endl;
int main() {
    long long a,b;
    while(cin >> a >> b)print(a,b)
    return 0;
}