#include "class.h"
void dealwithtask(string task);
int main()
{
string task1="(:task (open X) (:cond (sort X microwave)))",
task2="(:task (takeout X Y) (:cond (sort X cup) (color X red) (sort Y microwave)))",
task3="(:task (takeout X Y) (:cond (sort X book) (sort Y cupboard))) ",
task4="(:task (takeout X Y) (:cond (sort X can) (color X yellow) (sort Y cupboard))) ";
dealwithtask(task2);
// dealwithtask(task1);
// dealwithtask(task4);
// dealwithtask(task3);
return 0;
}
void dealwithtask(string task)
{
int first,end,i,j,j1,k,l,count=0;
string str,str1,str2,str3;
/************************************************************************************/
if(task.find("open" )!=-1) first = task.find("open");//open (A) A:container
if(task.find("close" )!=-1) first = task.find("close");//close(B)B:container
if(task.find("takeout" )!=-1) first = task.find("takeout");//takeout(A,B)
if(task.find("putin" )!=-1) first = task.find("putin");//putin(A,B)
if(task.find("move" )!=-1) first = task.find("move");//move(A)
if(task.find("pickup" )!=-1) first = task.find("pickup");//pickup(A)
if(task.find("putdown" )!=-1) first = task.find("putdown");//putdown(A)
if(task.find("toplate" )!=-1) first = task.find("toplate");//toplate(A)
if(task.find("fromplate")!=-1) first = task.find("fromplate");//fromplate(A)
/********************************************************************************/
if(task.find(")))" )!=-1) end = task.find(")))");
str = task.substr(first-1,end-first+2); //update task
l =str.length();
/************************第一轮截取*************************************************/
i = str.find("(");
j = str.find(" ");
k = str.find(")");
while(k<str.length())
{
j1 = str.find(' ', j + 1);
str1 = str.substr(i + 1, j - i - 1);
if (j1>j&&j1<k)
{
str2 = str.substr(j + 1, j1 - j - 1);
str3 = str.substr(j1 + 1, k - j1 - 1);
}
if (j1>k || j1 == -1)
{
str2 = str.substr(j + 1, k - j - 1);
str3 = "**";
}
i = str.find('(', k);
j = str.find(' ', i);
k = str.find(')', i);
/*******************************************************************************/
cout<<str<<endl;
cout<<str1<<"\t\t"
<<str2<<"\t"
<<str3<<endl;
cout<<first<<endl<<endl<<endl;
/*********************************消去cond*** **********************************/
if(str.find("cond")!=-1)
str=str.substr(str.find("cond")+5);
+ cout<<str<<endl;
l =str.length();
// break;
}
void dealwithtask(string task);
int main()
{
string task1="(:task (open X) (:cond (sort X microwave)))",
task2="(:task (takeout X Y) (:cond (sort X cup) (color X red) (sort Y microwave)))",
task3="(:task (takeout X Y) (:cond (sort X book) (sort Y cupboard))) ",
task4="(:task (takeout X Y) (:cond (sort X can) (color X yellow) (sort Y cupboard))) ";
dealwithtask(task2);
// dealwithtask(task1);
// dealwithtask(task4);
// dealwithtask(task3);
return 0;
}
void dealwithtask(string task)
{
int first,end,i,j,j1,k,l,count=0;
string str,str1,str2,str3;
/************************************************************************************/
if(task.find("open" )!=-1) first = task.find("open");//open (A) A:container
if(task.find("close" )!=-1) first = task.find("close");//close(B)B:container
if(task.find("takeout" )!=-1) first = task.find("takeout");//takeout(A,B)
if(task.find("putin" )!=-1) first = task.find("putin");//putin(A,B)
if(task.find("move" )!=-1) first = task.find("move");//move(A)
if(task.find("pickup" )!=-1) first = task.find("pickup");//pickup(A)
if(task.find("putdown" )!=-1) first = task.find("putdown");//putdown(A)
if(task.find("toplate" )!=-1) first = task.find("toplate");//toplate(A)
if(task.find("fromplate")!=-1) first = task.find("fromplate");//fromplate(A)
/********************************************************************************/
if(task.find(")))" )!=-1) end = task.find(")))");
str = task.substr(first-1,end-first+2); //update task
l =str.length();
/************************第一轮截取*************************************************/
i = str.find("(");
j = str.find(" ");
k = str.find(")");
while(k<str.length())
{
j1 = str.find(' ', j + 1);
str1 = str.substr(i + 1, j - i - 1);
if (j1>j&&j1<k)
{
str2 = str.substr(j + 1, j1 - j - 1);
str3 = str.substr(j1 + 1, k - j1 - 1);
}
if (j1>k || j1 == -1)
{
str2 = str.substr(j + 1, k - j - 1);
str3 = "**";
}
i = str.find('(', k);
j = str.find(' ', i);
k = str.find(')', i);
/*******************************************************************************/
cout<<str<<endl;
cout<<str1<<"\t\t"
<<str2<<"\t"
<<str3<<endl;
cout<<first<<endl<<endl<<endl;
/*********************************消去cond*** **********************************/
if(str.find("cond")!=-1)
str=str.substr(str.find("cond")+5);
+ cout<<str<<endl;
l =str.length();
// break;
}
}
此程序出现逻辑错误的原因是因为循环体内i,j,k的值没有随着字符串的更新而更新