[解题报告] CSDN竞赛第六期

CSDN编程竞赛报名地址:https://edu.csdn.net/contest/detail/16

1. 严查枪火

题目

X国最近开始严管枪火。
像是"ak", “m4a1”, “skr”。都是明令禁止的。
现在小Q查获了一批违禁物品其中部分是枪支。
小Q想知道自己需要按照私藏枪火来关押多少人。
(只有以上三种枪被视为违法)

输入描述:
第一行输入整数n.(1 <= n <= 10000)表示携带违禁物品的人数。
以下n行表示违禁物品的名称。

输出描述:
输出需要按照私藏枪火来关押的人。

示例:
输入
4
aj
m4a1
skr
sc

输出
2

解题报告

模拟

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

int main() {
    int n, s = 0;
    string a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a == "ak" || a == "m4a1" || a == "skr") {
            ++s;
        }
    }
    printf("%d\n", s);
    return 0;
}

2. 鬼画符门

题目

鬼画符门,每年都会统计自己宗门鬼画符消耗的数量。
往年一直是大师兄管理。
但是大师兄谈恋爱了!!怎么能让这种事耽误自己恋爱时间呢!!
鬼艺接手了!!
你能帮鬼艺写一个程序统计每年消耗数量最多的鬼画符吗?

输入描述:
第一行输入整数n.(1 <= n <= 1000)
以下n行输入n个字符串。

输出描述:
输出答案字符串。

示例:
输入
5
red
red
green
grenn
hen

输出
red

解题报告

模拟

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
using namespace std;
map<string, int> h;

int main() {
    int n, s = 0;
    string a, ans;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        ++h[a];
    }
    for (map<string, int>::iterator it = h.begin(); it != h.end(); ++it) {
        if (it->second > s) {
            s = it->second;
            ans = it->first;
        }
        s = max(s, it->second);
    }
    cout << ans << endl;
    return 0;
}

3. 收件邮箱

题目

已知字符串str,str表示邮箱的不标准格式。
其中".“会被记录成"dot”,“@“记录成"at”。
写一个程序将str转化成可用的邮箱格式。(可用格式中字符串中除了开头结尾所有"dot”, 都会被转换, "at"只会被转化一次,开头结尾的不转化)

输入描述:
输入字符串str.(1 <= strlen(str) <= 1000)

输出描述:
输出转化后的格式。

示例:
输入
mxyatoxcoderdotcom

输出
mxy@oxcoder.com

解题报告

模拟

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

int main() {
    string a;
    cin >> a;
    int n = a.length();
    int x = a.find("at", 1);
    if (x < n - 2) {
        a = a.replace(x, 2, "@");
    }
    x = a.find("dot", 1);
    while (x > 0 && x < n - 3) {
        a = a.replace(x, 3, ".");
        x = a.find("dot", 1);
        n = a.length();
    }
    cout << a << endl;
    return 0;
}

4. 最长递增的区间长度

题目

给一个无序数组,求最长递增的区间长度。如:[5, 2, 3, 8, 1, 9] 最长区间 2, 3, 8 长度为 3

输入描述:
第一行输入整数n。(1 <= n <= 10000)表示数组的大小
第二行给出n个整数a.(-1e9 <= a <= 1e9)

输出描述:
nan

输入样例:
6
5 2 3 8 1 9

输出样例:
3

解题报告

模拟

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 10005
int a[N];

int main() {
    int n, s = 1, ans = 1;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        if (i > 0 && a[i] > a[i - 1]) {
            ++s;
        }
        else {
            s = 1;
        }
        ans = max(ans, s);
    }
    printf("%d\n", ans);
    return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值