View Code of Problem 105

#include<bits/stdc++.h>
using namespace std;
int main() {
	string s,s2;
	int n;
	while(cin>>s) {
		if(s=="END") break;
		cin>>n;
		for(int i=0; i<n; i++) {
			cin>>s2;
			cout<<i+1<<" ";
			if(s2.length()==s.length()) {//修改或者正确 
				int flag=1, j; 
				for(j=0; j<s.length(); j++) {
					if(s[j]!=s2[j]) {
						flag=0; 
						break;
					}
				}
				if(flag) cout<<"OK!"<<endl;
				else cout<<j+1<<" change "<<s[j]<<endl; 
			}else if(s2.length()>s.length()) {//删除 
				int j;
				for(j=0; j<s.length(); j++) {
					if(s[j]!=s2[j]) break;
				}
				for(;j>=1; ) {
					if(s2[j]==s2[j-1]) j--;
					else break;
				}
				cout<<j+1<<" delete "<<s2[j]<<endl;
			}else {//插入 
				int j;
				for(j=0; j<s2.length(); j++) {
					if(s[j]!=s2[j]) break;
				}
				for(;j>=1; j--) {
					if(s[j]!=s[j-1]) break;
				}
				cout<<j+1<<" insert "<<s[j]<<endl;
			}
		}
	}
} 

Double click to view unformatted code.


Back to problem 105