[noj 1521] +-字符串
来源:互联网 发布:stm32官方烧录软件 编辑:程序博客网 时间:2024/05/17 01:37
题目链接:http://acm.nbut.cn/Problem/view.xhtml?id=????(OJ打不开了 = =、)
那么我们从最后一个数开始查找,如果相等,往前移一位,在判断是否相等,反复多次找到相等的后使count+=j-t;count表示交换次数,j表示下面的字符串j位置的字符,t表示上面字符串t位置的字符。
代码如下:
#include<stdio.h>
#include<string.h>
char s1[5005];
char s2[5005];
int main()
{
while(~scanf("%s",s1))
{
int count = 0;
scanf("%s",s2);
int len1 = strlen(s1);
int len2 = strlen(s2);
int len = len1;
for(int i = len-1,j = len - 1;i>=0;i--,j--)
{
if(s1[i]==s2[j])
{
continue;
}
else
{
int t = i;
while(t--)
{
if(s1[t]==s2[j])
{
int temp = s1[t];
s1[t] = s1[j];
s1[j] = temp;
count+=j-t;
break;
}
}
}
}
if(strcmp(s1,s2)==0)
printf("%d\n",count);
else
printf("-1\n");
}
return 0;
}
黑赵晓,我们特专业!
- [noj 1521] +-字符串
- NOJ [1521] +-字符串
- NOJ 字符串排序 1023
- NOJ 1023 字符串排序
- NOJ-1682 递减字符串问题
- Noj
- NOJ第56——字符串排序
- NOJ[1093] HTML 即HDU1088 对字符串的处理
- NOJ [1307] English Magic 字符串转化 3种操作 加1 减1 交换相邻字符
- NOJ 176
- NOJ 175
- NOJ 179
- NOJ 141
- NOJ 214
- NOJ 147
- NOJ 1242
- NOJ 1848
- NOJ 1610
- [noj 1395] 乾坤大挪移 (树状数组,归并排序)
- struts1和struts2的区别是什么?
- [1264] Flandre\'s First Escape
- 如下面一段代码打印结果为:true
- NOJ1293
- [noj 1521] +-字符串
- 【转载】[hrbust 2029] 二十世纪八十年代(状态压缩)
- [noj1393] 哦妈咪妈咪吼
- NOJ [1060] Countless Core Computers
- [HDOJ 1556] Color the ball(线段树成段更新入门)
- nbut 1058 火烧赤壁 2
- 杨辉三角
- [nbut 1405] bridge and island
- [1411] TT要吃肉