Monday, March 16, 2015

Solution of Codeforces 490A. Team Olympiad

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
#define size 5005
int arr[size],  a1[size], a2[size], a3[size];

int min(int c1, int c2,int c3)
{
    if(c1<=c2 && c1<=c3)
    {
        return c1;
    }
    else if (c2<=c1 && c2<=c3)
    {
        return c2;
    }
    else
    {
        return c3;
    }
}

int main()
{
    int n, i;
    int count1 , count2, count3;
    int index1, index2, index3;
    sf("%d", &n);

    for(i=1; i<=n; i++)
    {
        sf("%d", &arr[i]);
    }
    count1=count2=count3=0;
    index1=index2=index3=1;
    for(i=1; i<=n; i++)
    {
        if(arr[i]==1)
        {
            a1[index1++] = i;
            count1++;
        }
        if(arr[i]==2)
        {
            a2[index2++] = i;
            count2++;
        }
        if(arr[i]==3)
        {
            a3[index3++] = i;
            count3++;
        }
    }
    int team = min(count1, count2, count3);
    pf("%d\n", team);
    for(i=1; i<=team; i++)
    {
        pf("%d %d %d\n", a1[i], a2[i], a3[i]);
    }
    return 0;
}




Thursday, February 5, 2015

Solution of 379A. New Year Candles (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    int a, b, div, mod;
    sf("%d%d", &a, &b);
    int sum = a;
    while(a>=b)
    {
        div = (a/b);
        sum = sum + div;
        mod = (a%b);
        a= (div+mod);
    }
    pf("%d\n", sum);
}

Solution of 228A. Is your horseshoe on the other hoof? (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    int count, ans;
    ll s1, s2, s3, s4;
    cin >> s1 >> s2 >> s3 >> s4;
    ans=0;
    count = 1;
    if(s1!=s2 && s1!=s3 && s1!=s4)
    {
        count++;
    }
    if(s2!=s3 && s2!=s4)
    {
        count++;
    }
    if(s3!=s4)
    {
        count++;
    }
    ans = (4-count);
    cout << ans << endl;
}

Solution of 467A. George and Accommodation (Codeforces)



#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    int n, p, q, seat;
    sf("%d", &n);
    int count = 0;
    while(n--)
    {
        sf("%d%d", &p, &q);
        seat = (q-p);
        if(seat>=2)
        {
            count++;
        }
    }
    pf("%d\n", count);
}

Solution of 460A. Vasya and Socks (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    int a, b, div, mod;
    sf("%d%d", &a, &b);
    int sum = a;
    while(a>=b)
    {
        div = (a/b);
        sum = sum + div;
        mod = (a%b);
        a= (div+mod);
    }
    pf("%d\n", sum);
}

Solution of 110A. Nearly Lucky Number (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    ll len = s.length();
    ll count =0;
    for(int i=0; i<len; i++)
    {
        if(s[i]=='7' || s[i]=='4')
        {
            count++;
        }
    }
    if(count == 4 || count == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

}

Solution of 236A. Boy or Girl (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    char s[105];
    cin >> s;
    int len = strlen(s);
    sort(s, s+len);
    int count =0;
    for(int i=0; i<len; i++)
    {
        if(s[i] != s[i+1])
        {
            count++;
        }
    }
    if(count%2==0)
    {
        pf("CHAT WITH HER!\n");
    }
    else
    {
        pf("IGNORE HIM!\n");
    }
}

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...