Tuesday, May 31, 2016

CODEFORCES problem 231A Team

Problem link (Click here)

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int p,v,t;
    int solve = 0;
    for(int i=0;i<n;i++){
        cin>> p >> v >> t;
        if(p+v+t>1)
            solve++;
    }
    cout << solve << endl;

    return 0;
}

CODEFORCES problem 236A Boy or Girl

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <cstring>
#include<algorithm>

using namespace std;

int main()
{
    char word[100];
    cin>>word;
    int length=strlen(word);
    sort(word,word+length);
    int i, count = 0;
    for(i=0; i<length; i++){
        if(word[i]!=word[i+1]){
            count++;
        }
    }
    if(count%2==0)
        cout<<"CHAT WITH HER!"<<endl;

    else
        cout<<"IGNORE HIM!"<<endl;

    return 0;
}

CODEFORCES problem 546A Soldier and Bananas

Problem link (Click here)

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int k,n,w;
    int rate;
    int cost=0;
    int loan;
    cin>> k >> n >> w;
    for(int i=1; i<=w; i++){
        rate=i*k;
        cost=cost+rate;
    }
    loan=cost-n;
    if(loan<0)
        loan=0;
    cout<<loan<<endl;

    return 0;
}

VECTOR // STACK // QUEUE // SET

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <vector>
#include <conio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
/*vector <int> v;
v.push_back(12);
v.push_back(2);
v.push_back(15);
v.push_back(20);

int length=v.size();
sort(v.begin(),v.end());
cout<<length<<endl;
for(int i=0; i<length; i++)
cout<<v[i]<<endl;
*/

/*
stack <char> st;
st.push('b');
st.push('c');
st.push('d');
st.push('e');
while (1){
int status = st.empty();
if(status == 1){
            break;
}
//char tm= st.top();
cout<<st.top()<< endl;
st.pop();
}

*/
    set <int> s;
    s.insert(10);
    s.insert(5);
    s.insert(10);
    s.insert(10);
    s.insert(5);
    s.insert(1);
    cout<< s.size()<<endl;




getchar();
getchar();
    return 0;
}

MISSING ELEMENT IN AN ARRAY

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <vector>
#include <conio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
    vector <int> v;
    int n, i,temp;
    int miss;
    cin >> n;
    for(i=0; i<n; i++){
        cin>> temp;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    int a=v[0];
    int b=0;

for(i=a; i<a+n; i++){
        if(v[b]!=i){
            miss=i;
            break;
        }
        b++;
}
    cout<< "Missing elemnet : "<<miss<< endl;

getchar();
getchar();
    return 0;
}





FINDING ARRAY IS SORTED

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <vector>
#include <conio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
    vector <int> v;
    int n, i,temp;
    int count=0;
    cin >> n;
    for(i=0; i<n; i++){
        cin>> temp;
        v.push_back(temp);
    }

for(int i=0; i<n-1; i++){
        if(v[i]<v[i+1]){
            count++;
        }
}
if (count==n-1)
        cout<< "Sort"<<endl;
    else
        cout<< "Not Sort"<<endl;

getchar();
getchar();
    return 0;
}




WHETHER TWO ARRAY IS SAME USING VECTOR

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <vector>
#include <conio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
    vector <int> v1;
    vector <int> v2;
    int n, i,temp;
    int count=0;;
    cin >> n;
    for(i=0; i<n; i++){
        cin>> temp;
        v1.push_back(temp);
    }
    for(i=0; i<n; i++){
        cin>> temp;
        v2.push_back(temp);
    }
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());

for(int i=0; i<n; i++){
        if(v1[i]==v2[i]){
            count++;
        }
}
if (count==n)
        cout<< "Same"<<endl;
    else
        cout<< "Not Same"<<endl;

getchar();
getchar();
    return 0;
}



UNIQUE NUMBER USING SET

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <vector>
#include <conio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{

    set <int> s;
    int temp;
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>temp;
        s.insert(temp);
    }
    cout<< s.size()<<endl;

getchar();
getchar();
    return 0;
}


CODEFORCES problem 148A Insomnia cure

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>

using namespace std;

int main()
{
    int i,k,l,m,n,d;
    int count=0;
    cin>>k>>l>>m>>n>>d;
    for(i=1;i<=d;i++){
        if(i%k==0||i%l==0||i%m==0||i%n==0)
            count++;
    }
    cout<<count<<endl;

    return 0;
}

Monday, May 30, 2016

CODEFORCES problem 58/A Chat room

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>

using namespace std;

int main()
{
    string word="hello";
    string type;
    cin>>type;
    int length=type.length();
    int a=0;
    int i, count = 0;
    for(i=0; i<length; i++){
        if(type[i]==word[a]){
            a++;
            count++;
        }
    }
    if(count==5)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}

CODEFORCES problem 282/A Bit++

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>

using namespace std;

int main()
{
    string ch;
    int n;
    int x=0;
    cin >> n;
    while(n--){
        cin>>ch;
        if(ch[0]=='+' || ch[1]=='+'){
            x++;
        }
        else
            x--;
    }
    cout<< x <<endl;

    return 0;
}

CODEFORCES problem 122/A Lucky Division

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>

using namespace std;

int main()
{
    string num;
    int count=0,i;
    cin >> num;
    int a = atoi(num.c_str());
    int len=num.length();
    for(i=0; i<len; i++){
        if(num[i]=='4' || num[i]=='7')
            count++;
    }
    if(count==len)
        cout<<"YES"<<endl;
    else if(a%47==0)
        cout<<"YES"<<endl;
    else if (a%4==0 || a%7==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;


    return 0;
}

Sunday, May 29, 2016

CODEFORCES problem 96/A Football

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    string team ;
    int i;
    int a=0, b=0;
    int length;
    cin >> team;
    length = team.size();
    for(i=0; i< length; i++){
        if(team[i]== '1'){
            a++;
            b=0;
        }
        else if(team[i]== '0'){
            b++;
            a=0;
        }
        if(a >= 7 || b >= 7)
            break;
    }

    if(a >= 7 || b >= 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

CODEFORCES problem 467/A George and Accommodation

Problem link (Click here)

#include <iostream>
#include <cstdio>


using namespace std;

int main()
{
    int i, p, q, free, count=0;
    cin >> i;
    while(i--){
        cin >> p >> q;
        free = q-p;
        if(free>=2)
            count++;
    }
    cout << count << endl;

    return 0;
}

Wednesday, May 11, 2016

CODEFORCES problem 281/A Word Capitalization

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    string stone ;
    int i=0;
    cin >> stone;
    stone[i]=toupper(stone[i]);

    cout << stone << endl;
    return 0;
}

CODEFORCES problem 266/A Stones on the Table

Problem link (Click here)

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    string stone ;
    int count= 0;
    int n;
    cin >>n >> stone;
    for(int i = 1; i < n; i++ ){
        if(stone[i]==stone[i-1])
            count++;
    }

    cout << count << endl;
    return 0;
}

CODEFORCES problem 133/A HQ9+

Problem link (Click here)

#include<cstdio>
#include <iostream>
#include <Cstring>

using namespace std;

int main()
{
    char a[100];
    int flag=0;
    gets(a);
    for(int i=0; i<strlen(a); i++){
        if(a[i]== 'H' || a[i]== 'Q' || a[i]== '9'){
            cout<<"YES"<<endl;
            flag++;
            break;
        }
    }
    if(flag==0)
        cout<<"NO"<<endl;

    return 0;
}

CODEFORCES problem 339/A Helpful Maths

Problem link (Click here)

#include<cstdio>
#include <cstdlib>
#include <iostream>
#include <Cstring>
#include <algorithm>
using namespace std;

int main()
{
    char a[100];
    int b[100];
    gets(a);
    int i, j=0,len=0;
    int length = strlen(a);
    for(i=0 ; i<length ; i++){
        if(a[i]== '1'|| a[i]== '2' || a[i]=='3' ){
            int c = atoi(&a[i]);
            b[j]=c;
            j++;
            len++;
        }
    }
    sort(b,b+len);
    for(i=0;i<len;i++){
        cout<<b[i];
        if(i<len-1)
            cout<<"+";
    }
    cout<<endl;
    return 0;
}


CODEFORCES problem 50/A Domino piling

Problem link (Click here)

#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int M,N;
    cin >> M >> N;
    int count=(M*N)/(2*1);
    cout << count << endl;
    return 0;
}

Monday, May 2, 2016

UVA problem 382 - Perfection

Problem link (Click here)

#include<cstdio>
#include <iostream>

using namespace std;

int main()
{
    int n,i,sum;
    printf("PERFECTION OUTPUT\n");
    while(scanf("%d",&n)==1){
        if(n==0)
            break;
        else
            {
                sum=0;
                for(i=1;i<=n/2;i++){
                    if(n%i==0)
                        sum=sum+i;
                }
                if(n<10)
                    printf("    ");
                else if(n<100)
                    printf("   ");
                else if(n<1000)
                    printf("  ");
                else if(n<10000)
                    printf(" ");
                if(sum==n)
                    printf("%d  PERFECT\n",n);
                else if(sum<n)
                    printf("%d  DEFICIENT\n",n);
                else
                    printf("%d  ABUNDANT\n",n);
            }
    }
    printf("END OF OUTPUT\n");

    return 0;
}

Sunday, May 1, 2016

UVA problem 12696 - Cabin Baggage

Problem link (Click here)

#include<cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int test_case, count = 0;
    float length, width, depth, weight;

    cin >> test_case;
    while(test_case--)
    {
        cin>>length>>width>>depth>>weight;
        if((length<=56.00&&width<=45.00&&depth<=25.00||(length+width+depth)<=125.00)&&weight<=7.00){
            cout<<"1"<<endl;
            count++;
        }
        else
            cout<<"0"<<endl;
    }
    cout<<count<<endl;
    return 0;
}

UVA problem 11764 - Jumping Mario

Problem link (Click here)

#include<cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int test_case, c = 0;
    cin >> test_case;
    while(test_case--)
    {
        int total_wall, wall_height, wall = 0;
        int high_jump = 0;
        int low_jump = 0;
        c++;
        cin >> total_wall;
        while(total_wall--)
        {
            cin >> wall_height;
            if (wall == 0)
                wall = wall_height;
             else if(wall>wall_height)
                {
                    low_jump++;
                    wall = wall_height;
                }
             else if (wall<wall_height)
             {
                 high_jump++;
                 wall = wall_height;
             }
        }
        printf("Case %d: %d %d\n",c,high_jump,low_jump);
    }
    return 0;
}

UVA problem 11984 - A Change in Thermal Unit

Problem link (Click here)

#include<cstdio>
#include <iostream>
using namespace std;
int main()
{
    int test_case, t = 0;
    float f,a,c,d;
    cin >> test_case;
    while(test_case--)
    {
        t++;
        cin >> c >> d;
        f = 9*c/5+d;
        a = f*5/9;
        printf("Case %d: %.2f\n",t,a);

    }
    return 0;
}

UVA problem 12403 - Save Setu

Problem link (Click here)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int n,b;
    int report=0;
    string a;
    cin>>n;
    getchar();
    while(n--)
    {
        cin>>a;
        if(a=="donate"){
            cin>>b;
            report=report+b;
        }
        else
            printf("%d\n", report);
    }
    return 0;
}

UVA problem 11530 - SMS Typing

Problem link (Click here)

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    char a[1000];
    int i, n,test_case=0;
    scanf("%d",&n);
    getchar();
    while(n--){
        test_case++;
        int sum=0;
        gets(a);
        int l=strlen(a);
        for(i=0;i<l;i++){
            if(a[i]=='a')
                sum=sum+1;
            else if(a[i]=='b')
                sum=sum+2;
            else if(a[i]=='c')
                sum=sum+3;
            else if(a[i]=='d')
                sum=sum+1;
            else if(a[i]=='e')
                sum=sum+2;
            else if(a[i]=='f')
                sum=sum+3;
            else if(a[i]=='g')
                sum=sum+1;
            else if(a[i]=='h')
                sum=sum+2;
            else if(a[i]=='i')
                sum=sum+3;
            else if(a[i]=='j')
                sum=sum+1;
            else if(a[i]=='k')
                sum=sum+2;
            else if(a[i]=='l')
                sum=sum+3;
            else if(a[i]=='m')
                sum=sum+1;
            else if(a[i]=='n')
                sum=sum+2;
            else if(a[i]=='o')
                sum=sum+3;
            else if(a[i]=='p')
                sum=sum+1;
            else if(a[i]=='q')
                sum=sum+2;
            else if(a[i]=='r')
                sum=sum+3;
            else if(a[i]=='s')
                sum=sum+4;
            else if(a[i]=='t')
                sum=sum+1;
            else if(a[i]=='u')
                sum=sum+2;
            else if(a[i]=='v')
                sum=sum+3;
            else if(a[i]=='w')
                sum=sum+1;
            else if(a[i]=='x')
                sum=sum+2;
            else if(a[i]=='y')
                sum=sum+3;
            else if(a[i]=='z')
                sum=sum+4;
            else
                sum++;
            }
        printf("Case #%d: %d\n",test_case,sum);
    }

    return 0;
}

UVA problem 10783 - Odd Sum

Problem link (Click here)

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int i, j, n, a, b;
    int sum,test_case=0;
    cin>>n;
    for(i=0;i<n;i++){
        test_case++;
        sum=0;
        cin>>a>>b;
        if(a%2==0)
            a=a+1;
        if(b%2==0)
            b=b-1;
        for(j=a;j<=b;j=j+2)
            sum=sum+j;

        printf("Case %d: %d\n",test_case,sum);
    }
    return 0;
}

UVA problem 10921 - Find the Telephone

Problem link (Click here)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int i;
    char a[1000];
    while(scanf("%s",&a)!=EOF)
    {
        int b=strlen(a);
        for(i=0; i<b; i++){
            if(a[i]=='A'||a[i]=='B'||a[i]=='C')
                printf("2");
            else if(a[i]=='D'||a[i]=='E'||a[i]=='F')
                printf("3");
            else if(a[i]=='G'||a[i]=='H'||a[i]=='I')
                printf("4");
            else if(a[i]=='J'||a[i]=='K'||a[i]=='L')
                printf("5");
            else if(a[i]=='M'||a[i]=='N'||a[i]=='O')
                printf("6");
            else if(a[i]=='P'||a[i]=='Q'||a[i]=='R'|a[i]=='S')
                printf("7");
            else if(a[i]=='T'||a[i]=='U'||a[i]=='V')
                printf("8");
            else if(a[i]=='W'||a[i]=='X'||a[i]=='Y'||a[i]=='Z')
                printf("9");
            else
                printf("%c",a[i]);
        }
        printf("\n");
    }

    return 0;
}

UVA problem 12250 - Language Detection

Problem link (Click here)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int cases=0;
    string str;
    while(1)
    {
        cases++;
        cin>>str;
        if(str=="HELLO")
            printf("Case %d: ENGLISH\n", cases);
        else if( str=="HOLA")
            printf("Case %d: SPANISH\n", cases);
        else if( str=="HALLO")
            printf("Case %d: GERMAN\n", cases);
        else if( str=="BONJOUR")
            printf("Case %d: FRENCH\n", cases);
        else if( str=="CIAO")
            printf("Case %d: ITALIAN\n", cases);
        else if( str=="ZDRAVSTVUJTE")
            printf("Case %d: RUSSIAN\n", cases);
        else if( str=="#")
            break;
        else
            printf("Case %d: UNKNOWN\n", cases);
    }
    return 0;
}