这是我的代码
#include
#include
#include
#include
#include
using namespace std;
int getInt(string &s)
{
istringstream iss(s);
int num, res = 0;
while(iss >> num)
res++;
return res;
}
void getInt(string &s,int b[],int n)
{
istringstream iss(s);
int num, res = 0;
while(iss >> num)
{
b[res++]=num;
}
}
int index(int n,int b[],int count)
{
for(int i=0;i
{
if(b[i]==n)return i;
}
}
void move(int b[],int ind,int tag1)
{
int a = b[ind];
for(int i=ind;i>tag1;i--)
{
b[i]=b[i-1];
}
b[tag1] =a;
}
bool infind(int b1[],int b2[],int count)
{
for(int i=0;i
{
if(b1[i]!=b2[i])return false;
}
return true;
}
int main()
{
int q;
cin>>q;
while(q--)
{
cin.clear();
cin.sync(); //每次都要刷新缓冲流
string s1,s2;
getline(cin,s1);
getline(cin,s2);
int count = getInt(s1);
int *b1 = new int[count]; //原序列
int *b2 = new int[count]; //目标序列
int *b3 = new int[count];
getInt(s1,b1,count);
getInt(s2,b2,count);
int tag1,tag2,jishu=0;
int countt = count;
for(int j=0;j<countt;j++)
{
for(int i=0;i<count;i++)
{
tag1=index(b2[i],b1,count);
tag2=i;
if(tag1>tag2) //开始移动
{
move(b1,tag1,tag2);
jishu++;
}
}
if(infind(b1,b2,count))break;
}
cout<<jishu<<endl;
}
}
要实现的功能是这张图片上的
OJ上出现这样的错误:
Runtime Error:[ERROR] A Not allowed system call: runid:78421 callid:140
这是为什么,哪里出现问题了