3748. 递增子串

最长上升子串,最长上升子序列的变形

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
26
27
28
29
30
31
#include <iostream>

using namespace std;

const int N = 2e5 + 5;
int a[N];

signed main()
{
int t;
cin >> t;
for (int k = 1; k <= t; k ++)
{
cout << "Case #" << k << ": ";
int n;
cin >> n;
string s;
cin >> s;
a[0] = 1;
for (int i = 1; i < s.size(); i ++)
{
a[i] = 1;
if (s[i] > s[i - 1])
a[i] += a[i - 1];
}
for (int i = 0; i < s.size(); i ++)
{
cout << a[i] << " \n"[i == s.size() - 1];
}
}
}

3325. Kick_Start

统计”kick”的数量,每次遇到”start”时,答案加上”kick”的数量,使用substr函数

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
26
27
28
#include <iostream>

using namespace std;

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int t;
cin >> t;
for (int k = 1; k <= t; k ++)
{
cout << "Case #" << k << ": ";

int kick = 0, ans = 0;
string s;
cin >> s;
for (int i = 0; i < s.size() - 4; i ++)
{
if (s.substr(i, 4) == "KICK")
kick++;
if (s.substr(i, 5) == "START")
ans += kick;
}

cout << ans << endl;
}
}

4736. 步行者

根据题意模拟即可

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

const int N = 32, M = 1005;
int a[M][N];

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int t;
cin >> t;
for (int k = 1; k <= t; k ++)
{
cout << "Case #" << k << ": ";
int m, n, p;
cin >> m >> n >> p;
for (int i = 1; i <= m; i ++)
{
for (int j = 1; j <= n; j ++)
{
cin >> a[i][j];
}
}

int ans = 0;

for (int i = 1; i <= n; i ++)
{
int maxn = 0;
for (int j = 1; j <= m; j ++)
{
maxn = max(maxn, a[j][i]);
}
ans += maxn - a[p][i];
}

cout << ans << endl;
}
}