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

Solution of 339A. Helpful Maths ( 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 a[105];

int main()
{
    string s;
    int i, k, len;
    cin >> s;
    len = s.length();
    k=1;
    int count = 1;
    for(i=0; i<len; i++)
    {
        a[0] = s[0]-'0';
        if(s[i]=='+')
        {
            a[k] = s[i+1]-'0';
            k++;
            count++;
        }
    }
    sort(a, a+k);
    for(k=0; k<count; k++)
    {
        cout << a[k];
        if(k==(count-1))
        {
            break;
        }
        cout <<"+";
    }
}

Compare equality of two string in C

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