【codeforces 434 div 1 A】Did you mean...
2017-10-04 18:44
405 查看
【链接】h在这里写链接
【题意】
让你维护一段序列。 这段序列,不会出现连续3个以上的辅音。 (或者一块全是辅音则也可以) (用空格可以断开连续次数); 要求空格最小。
【题解】
模拟着,别让它出现连续三个辅音就好。 不到万不得已不加空格。 按照这个原则去贪心。
【错的次数】
0
【反思】
在这了写反思
【代码】
#include <bits/stdc++.h> using namespace std; const int N = 3e3; int n; int a[N+10],is[400]; char s[N + 10]; int main() { //freopen("F:\\rush.txt", "r", stdin); ios::sync_with_stdio(0), cin.tie(0); is['a'] = is['e'] = is['i'] = is['o'] = is['u'] = 1; cin >> (s+1); n = strlen(s + 1); int cnt = 0; for (int i = 1; i <= n; i++) { if (!is[s[i]]) { cnt++; if (cnt >= 3) { bool ok = true; int j = max(1, i - 2); for (int k = j; k <= i - 1; k++)//前面的3个都和它一样吗 if (s[k] != s[i]) ok = false; if (ok)//如果是的话 { cout << s[i]; int k = i; while (k + 1 <= n && s[k + 1] == s[i]) {//往后一直找和它一样的 k++; cout << s[k]; } cnt = 2; i = k;//cnt变成2了,指向下一个。 } else {//不是的话。只能分割了。 cout << ' '<<s[i]; cnt = 1; } } else { cout << s[i];//没3个 } } else {//是元音直接输出 cout << s[i]; cnt = 0; } } //连续出现 return 0; }
相关文章推荐
- Codeforces Round #434 (Div.2) - C - Did you mean...
- Codeforces 861 C. Did you mean... (模拟)
- Codeforces Round #434 Did you mean...
- make工具报错:missing separator (did you mean TAB instead of 8 spaces?). Stop.
- rubyzip NameError (uninitialized constant Zip::File Did you mean? File)
- *** missing separator (did you mean TAB instead of 8 spaces?)或者*** missing separator的解决办法
- cocoa Unknown type name 'class'; did you mean 'Class'? 问题的解决
- 【iOS开发-63】Unknown type name "CGRect",did you mean "Rect"?的解决方式
- brew 安装的.net 运行时提示"Did you mean to run dotnet SDK commands?"
- tensorflow调试之三:Variable foo/bar already exists, disallowed. Did you mean to set reuse=True or reuse=
- Unknown type name "CGRect",did you mean "Rect"?的解决方案
- cocoa Unknown type name 'class'; did you mean 'Class'? 问题解决
- BuildError: Could not build url for endpoint 'show'. Did you mean 'api.show' instead?
- makefile报错:Makefile: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.
- quartz使用时遇到的问题Bean property 'xxx' is not writable or has an invalid setter method. Did you mean 'xxx
- Bean property 'service' is not writable or has an invalid setter method. Did you mean 'serivce'?
- Bean property 'manualPaperService' is not writable or has an invalid setter method. Did you mean 'ma
- 导入android sdk samples工程报错"did you mean to use @+id instead of @+android:id?"
- 【iOS开发-63】Unknown type name "CGRect",did you mean "Rect"?的解决方案
- Codeforces 434 Div. 2 A