error prone
For the judgment of overwriting and underwriting, it is necessary to consider whether there are multiple consecutive letters
Description:
Who says college is easy? Is English also required to be dictated in college? Lux said Alexander for this. But in the eyes of the teacher, Lux is a very strange student, because for a word, Lux is either right or wrong. You'll say, what's so weird about this. But Lux is different. He makes one of three mistakes:
1: Missing a letter. eg: acm is written as am
2: one more letter is written. eg: acm is written as acmm
3: misspelled a letter. eg: acm is written as abm
Now, for a word, Lux wants you to tell him whether he wrote it right or wrong. If it is wrong, please tell him how to correct it.
Input:
There are multiple sets of inputs. End with "END".
The first row of each group is a correct word (word length does not exceed 2222).
The second line is a number m (m does not exceed 1111), indicating that Lux has dictated the word m times.
Next m lines, enter the words written by Lux.
Output:
For each dictation, if Lux writes correctly, it will output "OK!"; if it is wrong, you need to tell Lux how to correct it. The correction output format corresponding to the three situations is as follows:
1: x insert c means at the position of x Insert the letter c;
2: x delete c means to delete the letter c at the x position;
3: x change c means the letter at the x position should be changed to the letter c;
if there are multiple positions that can be changed, choose the first change method . (For details, see the sample output.) Remember to assign a serial number to each output, serial number 1-m;
Sample Input:
acm
4
am
acmm
abm
acm
END
Sample Output:
1 2 insert c
2 3 delete m
3 2 change c
4 OK!
#include<iostream>
#include<string>
using namespace std;
/**
* kkmd66
* @return
*/
int main() {
string str;
while (cin >> str && str != "END") {
int n;
cin >> n;
int flag = 1;
//n次听写
while (n--) {
string str2;
cin >> str2;
//若两字符串一样长
if (str.size() == str2.size()) {
int i;
for (i = 0; i < str.size(); i++) {
if (str[i] != str2[i]) {
cout << flag << " " << i + 1 << " change " << str[i] << endl;
flag++;
break;
}
}
//找到最后,没问题
if (i == str.size()) {
cout << flag << " OK!" << endl;
flag++;
}
}
//听写少了
else if (str.size() > str2.size()) {
for (int i = 0; i < str.size(); i++) {
if (str[i] != str2[i]) {
//可能出现ammm听写为amm的情况,要在最前面修改
if (str[i] == str2[i - 1]) {
while (str[i] == str2[i - 1])
i--;
}
cout << flag << " " << i + 1 << " insert " << str[i] << endl;
flag++;
break;
}
}
}
//听写多了
else {
for (int i = 0; i < str2.size(); i++) {
if (str[i] != str2[i]) {
//如果出现amm听写为ammm的情况
if (str2[i] == str2[i - 1]) {
while (str2[i] == str2[i - 1]) {
i--;
}
}
cout << flag << " " << i + 1 << " delete " << str2[i] << endl;
flag++;
break;
}
}
}
}
}
return 0;
}