Sunday, June 29, 2014

Codeforces Beta Round #97 (Div. 2), problem: (A) Presents solution

Codeforces Beta Round #97 (Div. 2), problem: (A) Presents: http://codeforces.com/problemset/problem/136/A

Codeforces Beta Round #97 (Div. 2), problem: (A) Presents editorial: http://codeforces.com/blog/entry/3353

Codeforces Beta Round #97 (Div. 2), problem: (A) Presents solution: http://ideone.com/c1Tez1

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

int main() {
    int n, a;
    map <int, int> p;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a), p[a]=i;
    for(int i=1; i<=n; i++) printf("%d ", p[i]);
    return 0;
}

Codeforces Good Bye 2013, problem: (A) New Year Candles solution

Codeforces Good Bye 2013, problem: (A) New Year Candles: http://codeforces.com/problemset/problem/379/A

Codeforces Good Bye 2013, problem: (A) New Year Candles editorial: http://codeforces.com/blog/entry/10171

Codeforces Good Bye 2013, problem: (A) New Year Candles solution: http://ideone.com/P4aKT2

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

int main() {
    int a, b, cnt=0;
    scanf("%d%d", &a, &b);
    cnt+=a;
    while(a>=b) {
        cnt+=a/b;
        a=a/b+a%b;
    }
    printf("%d", cnt);
    return 0;
}

Saturday, June 28, 2014

Codeforces Round #141 (Div. 2), problem: (A) Is your horseshoe on the other hoof? solution

Codeforces Round #141 (Div. 2), problem: (A) Is your horseshoe on the other hoof? : http://codeforces.com/problemset/problem/228/A

Codeforces Round #141 (Div. 2), problem: (A) Is your horseshoe on the other hoof? editorial: http://codeforces.com/blog/entry/5404

Codeforces Round #141 (Div. 2), problem: (A) Is your horseshoe on the other hoof? solution: http://ideone.com/a5XhpJ

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

int main() {
    int b=0, cnt=0;
    map <int, int> a;
    for(int i=0; i<4; i++) {
        scanf("%d", &b);
        a[b]++;
    }
    for(map <int, int>::iterator ii=a.begin(); ii!=a.end(); ii++) {
        if((*ii).second==4) cnt+=3;
        else if((*ii).second==3) cnt+=2;
        else if((*ii).second==2) cnt++;
    }
    printf("%d", cnt);
    return 0;
}

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year solution

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year: http://codeforces.com/problemset/problem/271/A

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year editorial: http://codeforces.com/blog/entry/6662

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year solution: http://ideone.com/sNbVJQ

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

int main() {
    int y, a[5]={0}, n, flag=0, i;
    scanf("%d", &y);
    n=y;
    while(1) {
        n++;
        y=n;
        i=0;
        flag=0;
        while(y>0) {
            a[i]=y%10;
            y/=10;
            i++;
        }
        for(int j=0; j<3; j++) {
            for(int k=j+1; k<4; k++) if(a[j]==a[k]) {flag=1; break;}
            if(flag==1) break;
        }
        if(flag==0) break;
    }
    for(int j=3; j>=0; j--) printf("%d", a[j]);
    return 0;
}

Codeforces Beta Round #84 (Div. 2 Only), problem: (A) Nearly Lucky Number solution

Codeforces Beta Round #84 (Div. 2 Only), problem: (A) Nearly Lucky Number: http://codeforces.com/problemset/problem/110/A

Codeforces Beta Round #84 (Div. 2 Only), problem: (A) Nearly Lucky Number editorial: http://codeforces.com/blog/entry/2547

Codeforces Beta Round #84 (Div. 2 Only), problem: (A) Nearly Lucky Number solution: http://ideone.com/xkzcsK


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

int main() {
    int cnt=0, a=0, r=0, p=0;
    char s[25];
    scanf("%s", s);
    for(int i=0; i<strlen(s); i++) if(s[i]=='4' || s[i]=='7') cnt++;
    while(cnt>0) {
        a=cnt%10;
        cnt/=10;
        p++;
        if(a==4 || a==7) r++;
    }
    if(r==p && r>0) printf("YES");
    else printf("NO");
    return 0;
}

Codeforces Round #146 (Div. 2), problem: (A) Boy or Girl solution

Codeforces Round #146 (Div. 2), problem: (A) Boy or Girl: http://codeforces.com/problemset/problem/236/A

Codeforces Round #146 (Div. 2), problem: (A) Boy or Girl editorial: http://codeforces.com/blog/entry/5592

Codeforces Round #146 (Div. 2), problem: (A) Boy or Girl solution: http://ideone.com/SdHXlb

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

int main() {
    int a[30]={0}, cnt=0;
    char s[105];
    scanf("%s", s);
    for(int i=0; i<strlen(s); i++) {
        if(a[s[i]-97]==0) cnt++;
        a[s[i]-97]++;
    }
    if(cnt%2==0) printf("CHAT WITH HER!");
    else printf("IGNORE HIM!");
    return 0;
}

Codeforces Round #172 (Div. 2), problem: (A) Word Capitalization solution

Codeforces Round #172 (Div. 2), problem: (A) Word Capitalization: http://codeforces.com/problemset/problem/281/A

Codeforces Round #172 (Div. 2), problem: (A) Word Capitalization editorial: http://codeforces.com/blog/entry/6939

Codeforces Round #172 (Div. 2), problem: (A) Word Capitalization solution: http://ideone.com/NHXJWx

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

int main() {
    char s[1005];
    gets(s);
    if(s[0]>=97) s[0]=toupper(s[0]);
    puts(s);
    return 0;
}