codeforces的题求分析代码错误
http://codeforces.com/problemset/problem/1015/B不知道哪里错了
#include <stdio.h>
#include <stdlib.h>
int key = 1, times = 0;
int fsame(char s[], char t[], int length, int dif);
void change(char s[], int flag[], int same, int dif);
int fsame(char s[], char t[], int length, int dif)//找到与t相同的s[]的引索值
{
int i;
for(i = dif + 1; i < length; i++)
{
if(s = t)
{
break;
}
}
if (i == length)
{
key = 0;
return -1;
}
return i;
}
void change(char s[], int flag[], int same, int dif)//用两两互换的方法将s转移到s
{
int i, temp;
for(i = same; i > dif; i--)
{
static int time = 0;//放在函数内部的循环体内和外是否有差异
temp = s;
s = s;
s = temp;
flag = i - 1;
time++;
times++;
}
}
int main()
{
int length, same;
char *s;
char *t;
int *flag;
scanf("%d",&length);
getchar();
s = (char *)calloc(length + 1,sizeof(char));
t = (char *)calloc(length + 1,sizeof(char));
flag = (int *)calloc(5000,sizeof(int));
scanf("%s",&s);
getchar();
scanf("%s",&t);
for(int i = 0; i < length; i++)
{
if(i == length - 1)
{
if(s = t) break;
else{
key = 0;
break;
}
}
if(s = t) continue;
else
{
if((same = fsame(s, t, length, i)) == -1) break;
change(s, flag, same, i);
}
}
if (key == 0) printf("0\n");
else
{
printf("%d\n",times);
for(int i = 0; i < times; i++)
{
printf("%d ",flag);
}
}
free(s);
free(t);
free(flag);
return 0;
}
页:
[1]