Codeforces Round #481 (Div. 3) B. File Name

题目地址:http://codeforces.com/contest/978/problem/B

题解:一串文件名里不能出现连续的xxx,询问进行几次操作后,文件名才不会出现xxx。

方法:只要遍历一遍字符串里有几个xxx就可以了。

代码:(代码较丑,欢迎大佬们批评指正)

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<string>
 6 #include<iostream>
 7 #include<map>
 8 #include<vector>
 9 #include<set>
10 #include<queue>
11 using namespace std;
12 const int inf = 0x3f3f3f3f;
13 int main()
14 {
15     int n;
16     char s[150];
17     scanf("%d", &n);
18     scanf("%s", s);
19     int ans = 0;
20     for (int i = 0; i < n;i++ )
21     {
22         if (s[i] == 'x' && s[i + 1] == 'x'&&s[i + 2] == 'x')
23             ans++;
24     }
25     printf("%d
", ans);
26     return 0;
27 }
原文地址:https://www.cnblogs.com/Tangent-1231/p/9041317.html