12261-high Score
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_ problem&problem=3413
Train of thought: Note that there are a number of a name in the case of a series of consecutive a, "go left, go right" judgment, take all the minimum value output.
Complete code:
/*0.016s*/
#include <bits/stdc++.h>
using namespace std;
Char str[1001];
int main ()
{
int t, SUM, Len, I, J, ans;
scanf ("%d\n", &t);
while (t--)
{
gets (str);
sum = 0, len = strlen (str);
for (i = 0; i < len; ++i)
sum + + min (str[i]-' a ', num-(str[i]-' a '));
Ans = sum + len-1;
for (int i = 1; i < Len; i++)
{
if (str[i] = = ' A ')
{for
(j = i + 1; j < len && Str[j] = = ' A '; ++J)
;
ans = min (ans, sum + min ((i-1) << 1) + Len-j, ((len-j) << 1) + i-1);
}
printf ("%d\n", ans);
}
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/