题目:给两个字符串A,B通过给定的操作,A->B;
感觉水题,瞎搞吧。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define INF 1e9+7;
using namespace std;
const int maxn = 100;
char a[maxn], b[maxn];
int stra(char x, char y) {
if(y>=x) return (y-x);
else return (y-'A'+'Z'-x+1);
}
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%s%s", a, b) != EOF)
{
int len = strlen(a), ans = INF;
sort(a, a+len);
sort(b, b+len);
for(int i = 0; i < len; i++) {
int sum = 0;
for(int j = 0; j < len; j++)
sum += stra(a[j], b[j]);
ans = min(ans, sum);
for(int j = len; j >= 0; j--) a[j] = a[j-1];
a[0] = a[len];
}
printf("%d\n", ans);
}
return 0;
}