Thursday, March 20, 2014

Codeforces Beta Round #77 (Div. 2 Only), problem: (A) Football solution

Codeforces Beta Round #77 (Div. 2 Only), problem: (A) Football: http://codeforces.com/problemset/problem/96/A

Codeforces Beta Round #77 (Div. 2 Only), problem: (A) Football solution: http://ideone.com/27pT88

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

int main() {
    int flag, cnt;
    char s[105];
    scanf("%s", s);
    cnt=flag=0;
    for(int i=1; i<strlen(s); i++) {
        if(s[i]==s[i-1]) cnt++;
        else cnt=0;
        if(cnt==6) {
            flag=1;
            printf("YES");
            break;
        }
    }
    if(flag==0) printf("NO");
    return 0;
}

Codeforces Beta Round #96 (Div. 2), problem: (A) HQ9+ solution

Codeforces Beta Round #96 (Div. 2), problem: (A) HQ9+: http://codeforces.com/problemset/problem/133/A

Codeforces Beta Round #96 (Div. 2), problem: (A) HQ9+ solution: http://ideone.com/jm2lt4

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main() {
    int flag;
    char s[105];
    gets(s);
    flag=0;
    for(int i=0; i<strlen(s); i++) {
        if(s[i]=='H' || s[i]=='Q' || s[i]=='9') {
            printf("YES");
            flag=1;
            break;
        }
    }
    if(flag==0) printf("NO");
    return 0;
}

Codeforces Beta Round #85 (Div. 2 Only), problem: (A) Petya and Strings solution

Codeforces Beta Round #85 (Div. 2 Only), problem: (A) Petya and Strings: http://codeforces.com/problemset/problem/112/A

Codeforces Beta Round #85 (Div. 2 Only), problem: (A) Petya and Strings solution: http://ideone.com/DIWRcB

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

int main() {
    char a[105], b[105];
    scanf("%s%s", a, b);
    for(int i=0; i<strlen(a); i++) {
        if(a[i]>96) a[i]-=32;
        if(b[i]>96) b[i]-=32;
    }
    printf("%d", strcmp(a, b));
    return 0;
}


Codeforces Beta Round #90, problem: (A) Epic Game solution

Codeforces Beta Round #90, problem: (A) Epic Game: http://codeforces.com/problemset/problem/119/A

Codeforces Beta Round #90, problem: (A) Epic Game solution: http://ideone.com/EpNdwC

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

int gcd(int u, int v) {
    if(u==v) return u;
    if(v==0) return u;
    if(u==0) return v;
    if(~u & 1) {
        if(v & 1) return gcd(u>>1, v);
        else return gcd(u>>1, v>>1)<<1;
    }
    if(u>v) return gcd(u-v, v);
    return gcd(v-u, u);
}

int main() {
    int a, b, n;
    scanf("%d%d%d", &a, &b, &n);
    while(n>=0) {
        if(n==0) {
            printf("1");
            break;
        }
        n-=gcd(a, n);
        if(n==0) {
            printf("0");
            break;
        }
        n-=gcd(b, n);
    }
    return 0;
}

Codeforces Round #163 (Div. 2), problem: (A) Stones on the Table solution

Codeforces Round #163 (Div. 2), problem: (A) Stones on the Table: http://codeforces.com/problemset/problem/266/A

Codeforces Round #163 (Div. 2), problem: (A) Stones on the Table solution: http://ideone.com/zTRo04

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

int main() {
    int cnt, n;
    char s[55];
    cnt=0;
    scanf("%d\n%s", &n, s);
    for(int i=1; i<strlen(s); i++) if(s[i]==s[i-1]) cnt++;
    printf("%d", cnt);
    return 0;
}

Wednesday, March 19, 2014

Codeforces Round #173 (Div. 2), problem: (A) Bit++ solution

Codeforces Round #173 (Div. 2), problem: (A) Bit++: http://codeforces.com/problemset/problem/282/A

Codeforces Round #173 (Div. 2), problem: (A) Bit++ solution: http://ideone.com/U6SD1p

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

int main() {
    int n, r;
    char s[5];
    r=0;
    scanf("%d", &n);
    while(n--) {
        scanf("%s", s);
        if(s[0]=='+' || s[1]=='+') r++;
        else r--;
    }
    printf("%d", r);
    return 0;
}

Codeforces Beta Round #95 (Div. 2), problem: (A) cAPS lOCK solution

Codeforces Beta Round #95 (Div. 2), problem: (A) cAPS lOCK: http://codeforces.com/problemset/problem/131/A

Codeforces Beta Round #95 (Div. 2), problem: (A) cAPS lOCK solution: http://ideone.com/ti8FJu

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

int main() {
    int a;
    char s[105];
    a=0;
    scanf("%s", s);
    for(int i=0; i<strlen(s); i++) if(s[i]<91) a++;
    if(s[0]>96 && a==strlen(s)-1) {
        printf("%c", s[0]-32);
        for(int i=1; i<strlen(s); i++) printf("%c", s[i]+32);
    }
    else if(a==strlen(s)) for(int i=0; i<strlen(s); i++) printf("%c", s[i]+32);
    else printf("%s", s);
    return 0;
}