标签:
字母转换
#include <iostream>
#include <string.h>
#include <stack>
using namespace std;
stack<char> minestack;
char data[25];
char plan[100];
char temp[100];
string aim;
string known;
bool TestPlan(int length)
{
//cout<<"Enter"<<endl;
int pos1 = 0,pos2 = 0;
for(int i = 0;i < length; i++)
if(plan[i]==‘i‘)
{
minestack.push(known[pos1]);
pos1++;
}
else
{
if(!minestack.empty())
{
temp[pos2] = minestack.top();
minestack.pop();
pos2++;
}
else
return false;
}
for(int i = 0;i < length/2;i++)
if(temp[i]!=aim[i])
return false;
return true;
}
bool CountNum(int length)
{
//cout<<"hello"<<endl;
if(plan[0]==‘o‘)
return false;
int count = 0;
for(int i = 0;i < length;i++)
if(plan[i]==‘i‘)
count++;
if(count*2==length)
return true;
else
return false;
}
void FindPlan(int length,int pos)
{
if(pos==length)
{
if(CountNum(length))
{
if(TestPlan(length))
{
for(int i = 0;i < length;i++)
cout<<plan[i]<<" ";
cout<<endl;
}
}
}
else
{
plan[pos] = ‘i‘;
FindPlan(length,pos+1);
plan[pos] = ‘o‘;
FindPlan(length,pos+1);
}
}
int main()
{
cin>>known>>aim;
//stack<char> minestack;
//minestack.push(known[0]);
//cout<<minestack.top()<<endl;
int pos = 0;
FindPlan(2*known.length(),pos);
return 0;
}
标签:
原文地址:http://www.cnblogs.com/lxk2010012997/p/4414905.html