【发布时间】:2019-11-07 23:15:20
【问题描述】:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
string vowel[] = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "z"};
string a;
while (a != "quit!") {
int b = 1;
cin >> a;
for (int i = 0; i < 20; i++) {
if (a.length() > 4 && a.substr(a.length() - 3 ) == vowel[i] + "or") {
a[a.length() - 2] = 'o';
a[a.length() - 1] = 'u';
a += 'r';
cout << a << "\n";
b = 0;
break;
}
//cout << i;
}
if (b == 1) {
cout << a << "\n";
}
}
}
由于某种原因,如果您输入一个长度大于 4 且不以辅音 +“或”结尾的字符串,整个程序就会停止。该程序甚至从不进入 if 语句。
【问题讨论】:
-
您是在谈论您的 while 还是 for 循环?因为您的描述现在谈论的是 for 循环,但您的标题指的是外部 while 循环
-
您的程序可能会崩溃,因为您的数组中的元素少于 20 个。
-
哦,哈哈,非常感谢
-
改用
vector,然后使用size()方法。 -
string vowel[]:你是说consonant吗?