Saturday, January 3, 2015

Solution of 1294 - Positive Negative Sign ( Light Oj )

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

int main()
{
    long long m, n, test, t, ans;
    scanf("%lld", &test);
    for(t=1; t<=test; t++)
    {
        scanf("%lld%lld", &n, &m);
        ans = (n*m)/2;
        printf("Case %lld: %lld\n", t, ans);
    }
}

Solution of 1000. A+B Problem ( Timus Online Judge )

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


int main()
{
    ll a, b;
    sf("%lld%lld", &a, &b);
    pf("%lld\n", a+b);
}

Solution of 1083. Factorials!!! ( Timus Online Judge )

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

int main()
{
    int n, len, i;
    ll ans=1;
    string s;
    cin >> n;
    cin >> s;
    len = s.length();
    for(i=n ; i>0 ; i =(i-len))
    {
        ans = (ans*i);
    }
    cout << ans << endl;
}


Solution of 1293. Eniya ( Timus Online Judge )

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


int main()
{
    int n, a, b;
    sf("%d%d%d", &n, &a, &b);
    pf("%d\n", (a*b*n*2));

}


Solution of 1086. Cryptography ( Timus Online Judge )

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define MAX 165000

long long prime[MAX];
long long status[MAX];

void getPrime()
{
    int i, j;
    long long n = MAX;
    int p=1;
    long long sq = sqrt(n);
    for(i=4 ; i<=n; i=i+2)
    {
        status[i] = 1;
    }
    for(i=3 ; i<=sq; i=i+2)
    {
        if(status[i]==0)
        {
            for(j=2*i; j<=n; j+=i)
            {
                status[j]=1;
            }
        }
    }

    for(i=2 ; i<=n ; i++)
    {
        if(status[i] == 0)
        {
            prime[p] = i;
            p++;
        }
    }
}

int main()
{
    int test, index;
    getPrime();
    scanf("%d", &test);
    while(test--)
    {
        cin >> index;
        cout << prime[index] << endl;
    }
}

Solution of 1409. Two Gangsters ( Timus Online Judge )

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

int main()
{
    int L, H, sum=0;
    sf("%d%d", &H, &L);
    sum = (L+H-1);
    pf("%d %d\n", (sum-H), (sum-L) );
}

Solution of 2012. About Grisha N. ( Timus Online Judge )

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


int main()
{
    int f;
    sf("%d", &f);
    if(f>=7)
    {
        pf("YES\n");
    }
    else
    {
        pf("NO\n");
    }
}

Compare equality of two string in C

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