2021工大杯题解-A

个人题解,和比赛官方无关,仅供参考

Changing problem statement during contest

It is well known that we should not change the problem statement during the contest. But, we also know that a company named “Hua***” liked to change problem statement during the contest .

There were some breathtaking errors in the problem statements during the 2021 ICPC Asia Regionals Online Contest (I). So, naturally, we needed to change these statements.

For example, problem A needs change. As we all know, the word “lexicographic” means "order of the dictionary(字典序), ‘a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols.’ ", but somehow the person who wrote this problem misinterpreted the word as “ascending”.

Naturally, during reasonable contests, what he needs to do is to update the testcase data, changing it from ascending order to lexicographic order, matching the problem statement, then rejudge all submissions of
this problem. But, he doesn’t think it that way. “Why changing testcase data while we can change the problem statement?” Surely he didn’t know that submitting “Wrong Answer” would add penalty(罚时) to the team’s time cost. I mean, otherwise, why would he do this?

Can you help him change all “lexicographic” to “ascending”?

Input

The first line of input contains a integer $n$. $(1 \leq n \leq 100)$.

In the following $n$ lines, each line contains a string. It is guaranteed that the length of the string is less than $100$ characters, and the string only contains a to z.

Output

Output updated problem statements, replace all lexicographic by ascending.

Examples

Example 1

Input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
14
print
the
labels
of
all
the
busiest
nodes
in
lexicographic
order
separated
by
spaces

Output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
print
the
labels
of
all
the
busiest
nodes
in
ascending
order
separated
by
spaces

Example 2

Input

1
2
1
whoalexicographic

Output

1
whoalexicographic

In the first example, we replace “lexicographic” on the 10th line to
“ascending”.

In the second example, we do nothing because we don’t need to replace
word containing “lexicographic”.

题解

题目难度:简单。

阅读题面之后会发现是一个非常简单的字符串比较。循环 $n$ 次,每次读入一个字符串,如果是lexicographic就替换为ascending就好了。

标准答案:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <string.h>
int main() {
char input_string[101];
// 注意,存储长度为100的字符串,数组长度需要是101
const char *lexicographic = "lexicographic";
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++ i) {
// scanf 传入的是地址
// input_string 是数组名字,本身就是地址,不需要加
// 取地址符 &
// 了解更多: https://zh.cppreference.com/w/c/language/array
scanf("%s", input_string);
if (strcmp(input_string, lexicographic) == 0) {
// 相等,输出ascending
printf("ascending\n");
} else {
// 不相等,原样输出
printf("%s\n", input_string);
}
}
// 别忘了return 0
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
// 定义字符串 a
string a;
// 读入
cin >> a;
// 如果等于lexicographic,就替换为ascending
if (a == "lexicographic") {
a = "ascending";
}
// 输出
cout << a << endl;
}
return 0;
}