Monday, March 16, 2015

488A - Giga Tower (Codeforces)

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

int check(ll n)
{
    int count = 0;
    if(n<0)
    {
          n=-n;
    }
    while(n)
    {
        if(n%10==8)
        {
            count++;
        }
        n=n/10;
    }
    return count;
}

int main()
{
    ll a;
    int count, f;
    cin >> a;
    f=0;
    while(1)
    {
        a++;
        f++;
        count = check(a);
        if(count>=1)
        {
           break;
        }
    }
    cout<< f << endl;
}

492A. Vanya and Cubes (Codeforces)

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

int main()
{
    int n, sum , temp, count, i;
    sf("%d", &n);
    count = 0;
    sum = 0;
    temp = 0;
    for(i=1;;i++)
    {
        sum = sum + i;
        temp = sum + temp;
        if(temp>n)
        {
            break;
        }
        count++;
    }
    pf("%d\n", count);
}

495A. Digital Counter (Codeforces)

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

int main()
{
    int stick[11] = {2, 7, 2 , 3, 3, 4, 2, 5, 1 ,2};
    int n, x;
    cin >> n;
    int n1, n2;
    n1 = (n%10);
    n2 = (n/10);
    x = stick[n1]*stick[n2];
    cout << x << endl;
}

499A - Watching a movie (Codeforces)

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

int main()
{
    int t = 0;
    int l, r, n, m, x;
    sf("%d%d", &n, &x);
    int sum ;
    int temp =0;
    for(int i=1; i<=n; i++)
    {
        sf("%d%d", &l, &r);
        sum = 0;
        while(1)
        {
             t = t+x;
             if(t>=l)
             {
                 t = (t-x);
                 sum = sum + (r-t);
                 t = t+sum;
                 break;
             }
        }
        temp = temp +sum;
    }
    pf("%d\n", temp);
}

501A. Contest (Codeforces)

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

int maxFunc(int a, int b)
{
    int A1= (3*a)/10;
    int A2 = a - ((a*b)/250);
    return max(A1, A2);
}

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int M = maxFunc(a, c);
    int V = maxFunc(b, d);
    if(M>V)
    {
        pf("Misha\n");
    }
    else if(V>M)
    {
        pf("Vasya");
    }
    else
    {
        pf("Tie\n");
    }
}

Solution of 508A. Pasha and Pixels (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define pf printf
#define sf scanf
#define MAX 1005

int sq[MAX][MAX];

int main()
{
    int n, m, k;
    int i, j, t, temp;
    sf("%d%d%d", &n, &m, &k);
    temp =0;
    for(t=1; t<=k; t++)
    {
        sf("%d%d", &i, &j);
        sq[i][j] = 1;
        if(!temp)
        {
            if(sq[i][j+1]==1 && sq[i+1][j] ==1 && sq[i+1][j+1]==1)
            {
                temp = t;
            }
            else if(sq[i][j+1]==1 && sq[i-1][j]==1 && sq[i-1][j+1]==1)
            {
                temp = t;
            }
            else if(sq[i][j-1]==1 && sq[i-1][j]==1 && sq[i-1][j-1]==1)
            {
                temp = t;
            }
            else if(sq[i][j-1]==1 && sq[i+1][j-1]==1 && sq[i+1][j]==1)
            {
                temp = t;
            }
        }
        else
        {
            break;
        }
    }
    pf("%d\n", temp);
}

Solution of 478A. Initial Bet (Codeforces)

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

int main()
{
    int a, b, c, d, e, sum=0;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    sum = (a+b+c+d+e);
    if(sum==0)
        printf("-1");
    else if(sum%5==0)
        printf("%d\n", sum/5);
    else
        printf("-1\n");
}


Compare equality of two string in C

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