View Code of Problem 105

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	while(getline(cin,a)&&a!="END")
	{
		int b;
		cin>>b;
		cin.get();
		for(int i=0;i<b;i++)
		{
			string c;
			cin>>c;
			cout<<i+1<<" ";
			if(a.length()==c.length())
			{
				for(int j=0;j<a.length();j++)
				{
					if(a[j]!=c[j])
					{
						cout<<j+1<<" "<<"change "<<a[j]<<endl;
						break;
					}
					else
					{
						if(j==a.length()-1)
							cout<<"OK!"<<endl;
					}
				}
			}
			else
			{
				if(a.length()>c.length())
				{
					for(int j=0;j<a.length();j++)
					{
						if(a[j]!=c[j])
						{
							int t;
							for( t=j-1;t>0;)
							{
								if(a[t]==a[j])t--;
							}
							cout<<t+1<<" "<<"insert "<<a[j]<<endl; //原来插入也要插到第一个出现的位置!!!!! 
							break;
						}
							
					}
				}
				else
				{
						for(int j=0;j<c.length();j++)
					{
						if(a[j]!=c[j])
						{
							if(c[j]==c[j-1])
							{
								cout<<j<<" "<<"delete "<<c[j]<<endl;
								break;
							}
							else
							{
								cout<<j+1<<" "<<"delete "<<c[j]<<endl;
								break;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 105