View Code of Problem 105

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<climits>
#include<cmath>
#include<unordered_map>
#include<set>

using namespace std;


int main()
{
	string str;
	while (getline(cin, str)) {

		//getchar();

		if (str == "END")
			break;

		int num;
		cin >> num;
		getchar();

		for (int i = 1; i <= num; i++) {

			string word;
			getline(cin, word);
			//getchar();

			if (word == str)
				cout << i << " " << "OK!" << endl;

			else if (word.size() == str.size()) {

				for (int j = 0; j < word.size(); j++) {

					if (str[j] != word[j]) {

						cout << i << " " << j + 1 << " change " << str[j] << endl;
						break;
					}
				}
			}

			else if (word.size() < str.size()) {

				int flag = 0;
				for (int j = 0; j < word.size(); j++) {

					if (str[j] != word[j]) {

						cout << i << " " << j + 1 << " insert " << str[j] << endl;
						flag = 1;
						break;
					}
				}

				if (flag == 0) {

					int pos = str.size() - 1;
					while (pos > 0 && str[pos] == str[pos - 1])
						pos--;

					cout << i << " " << pos + 1 << " insert " << str[str.size() - 1] << endl;
				}
					
			}

			else if(word.size() > str.size()){

				if (str[0] != word[0]) {

					cout << i << " " << 1 << " delete " << word[0] << endl;
					continue;
				}
					
				int flag = 0;

				for (int j = 1; j < str.size(); j++) {

					if (str[j] != word[j]) {

						flag = 1;
						if(word[j] == word[j - 1])
							cout << i << " " << j << " delete " << word[j] << endl;
						else
							cout << i << " " << j + 1 << " delete " << word[j] << endl;

						break;
					}
				}

				if (flag == 0) {

					int pos = word.size() - 1;

					while (pos > 0 && word[pos] == word[pos - 1])
						pos--;

					cout << i << " " << pos + 1 << " delete " << word[pos] << endl;
				}
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 105