一道算法题
跪求大佬解决。。。。题目是这样的:给定一字符串S,S非空,由小写字母组成,设v为S中元音字母的个数,c为辅音字母的个数。"a", "e", "i", "o", "u"为元音字母。其余为辅音字母。如果元音字母没有超过辅音字母的2倍,即v≤2c则称S是好的字符串。
现在给定S,找出其中最长的好的子串的长度,以及个数。子串是由原串中连续的几个字符组成的。
下面是我写的代码。。。。大多都AC了可还是有几个显示超时了。。附件里面有一个我通过不了的输入。。它的输出是66 23988


#include <cmath> #include <vector> #include <algorithm> #include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int lnum = 0; int n = 0; int inum,bnum; for(int i = 0; i < a.size();i++) { inum = bnum =0; for(int j = i; j < a.size();j++){ switch(a[j]){ case 'a': case 'e': case 'i': case 'o': case 'u': inum++; break; default: bnum++; break; } if(inum <= 2 * bnum){ if(j+1-i > n){ n = j+1-i; lnum = 0; } if(j+1-i == n){ lnum++; } } } } if(lnum == 0){ cout << "No solution" <<endl; } else{ cout << n <<" "<< lnum <<endl; } return 0; }


