CSDN编程竞赛报名地址:https://edu.csdn.net/contest/detail/16
X国最近开始严管枪火。
像是"ak", “m4a1”, “skr”。都是明令禁止的。
现在小Q查获了一批违禁物品其中部分是枪支。
小Q想知道自己需要按照私藏枪火来关押多少人。
(只有以上三种枪被视为违法)
输入描述:
第一行输入整数n.(1 <= n <= 10000)表示携带违禁物品的人数。
以下n行表示违禁物品的名称。
输出描述:
输出需要按照私藏枪火来关押的人。
示例:
输入
4
aj
m4a1
skr
sc
输出
2
模拟
#include
#include
#include
#include
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;
}
鬼画符门,每年都会统计自己宗门鬼画符消耗的数量。
往年一直是大师兄管理。
但是大师兄谈恋爱了!!怎么能让这种事耽误自己恋爱时间呢!!
鬼艺接手了!!
你能帮鬼艺写一个程序统计每年消耗数量最多的鬼画符吗?
输入描述:
第一行输入整数n.(1 <= n <= 1000)
以下n行输入n个字符串。
输出描述:
输出答案字符串。
示例:
输入
5
red
red
green
grenn
hen
输出
red
模拟
#include
#include
#include
#include
#include
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;
}
已知字符串str,str表示邮箱的不标准格式。
其中".“会被记录成"dot”,“@“记录成"at”。
写一个程序将str转化成可用的邮箱格式。(可用格式中字符串中除了开头结尾所有"dot”, 都会被转换, "at"只会被转化一次,开头结尾的不转化)
输入描述:
输入字符串str.(1 <= strlen(str) <= 1000)
输出描述:
输出转化后的格式。
示例:
输入
mxyatoxcoderdotcom
输出
mxy@oxcoder.com
模拟
#include
#include
#include
#include
#include
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;
}
给一个无序数组,求最长递增的区间长度。如:[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
#include
#include
#include
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;
}