字符串处理

2019_团体程序设计天梯赛-L1-2 6翻了(15 分)

样例

输入样例
it is so 666 really 6666 what else can I say 6666666666


输出样例
it is so 666 really 9 what else can I say 27

代码

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
	string s;
	getline(cin , s);
	int l = s.length();
	for(int i = 0 ; i < l ; i++) {
		int cnt = 0;
		if(s[i] == '6') {
			for(int j = i; j < l ; j++) {
				if(s[j] == '6') {
					cnt++;
				} else {
					break;
				}
			}
			if(cnt <= 3) {
			} else if(cnt <= 9) {
				printf("9");
				i += cnt - 1;
				continue;
			} else if(cnt > 9) {
				printf("27");
				i += cnt - 1;
				continue;
			}
		}
		printf("%c", s[i]);
	}
	return 0;
}

考场上心太急了,总想快点拿分,写的分支稀烂不能看,一交13分,注意策略要想好再下手吧,字符串得细致点想

相关文章: