【解题报告】Intel Code Challenge Elimination Round

题目链接


A. Broken Clock(Codeforces 722A)

思路

解决这个问题有两种方法。

第一种方法。分类讨论。

第二种方法。将所有合法的情况枚举出来放到集合中,然后从集合中查找是否有匹配的情况。

下面的代码采用第一种方法。

代码

#include <bits/stdc++.h>
using namespace std;

int a, h, m;

int main() {
    scanf("%d\n%d:%d", &a, &h, &m);
    if(a == 12) {
        if(h == 0) {
            h = 1;
        }
        else if(h > 12) {
            if(h < 20) {
                h = 12;
            }
            else if(h % 10 <= 2) {
                h = 10 + h % 10;
            }
            else {
                h = h % 10;
            }
        }
    }
    else {
        if(h > 23) {
            if(h < 30) {
                h = 23;
            }
            else if(h % 10 <= 3) {
                h = 20 + h % 10;
            }
            else {
                h = h % 10;
            }
        }
    }
    if(m > 59) {
        m = m % 10;
    }
    if(h / 10 == 0) {
        putchar('0');
    }
    printf("%d:", h);
    if(m / 10 == 0) {
        putchar('0');
    }
    printf("%d\n", m);
    return 0;
}

B. Verse Pattern(Codeforces 722B)

思路

每输入一行字符串就统计该行内有多少个元音字母就能解决该题了。

代码

#include <bits/stdc++.h>
using namespace std;

const int maxn = 110;
bool flag = true;
char b[maxn];
int n, cnt, len, a[maxn];
set <char> s;

int main() {
    s.insert('a');
    s.insert('e');
    s.insert('i');
    s.insert('o');
    s.insert('u');
    s.insert('y');
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    getchar();
    for(int i = 0; i < n; i++) {
        gets(b);
        len = strlen(b);
        cnt = 0;
        for(int j = 0; j < len; j++) {
            if(s.count(b[j])) {
                cnt++;
            }
        }
        if(cnt != a[i]) {
            flag = false;
        }
    }
    puts(flag ? "YES" : "NO");
    return 0;
}

C. Destroying Array(Codeforces 722C)

思路1

我们可以用一系列离散的点来代表被分裂的区间。例如 0,3,n+1 。这三个点代表区间 [1,n] 已经被分割成区间 [1,2] 和区间 [4,n] 。然后我们建立一个映射 data[] ,其中 d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值