好友
阅读权限10
听众
最后登录1970-1-1
|
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[dif]相同的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[same]转移到s[dis]
{
int i, temp;
for(i = same; i > dif; i--)
{
static int time = 0;//放在函数内部的循环体内和外是否有差异
temp = s;
s = s[i - 1];
s[i - 1] = temp;
flag[time] = 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;
}
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|