#include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define ull unsigned long long #define debug printf("debug\n")

using namespace std;

inline int read() { int res=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { res=res10+ch-'0'; ch=getchar(); } return resf; }

const int INF=0x3f3f3f3f; const int maxn=1e5+5;

template inline void chkmin(T &x,T y) {if(x>y) x=y;}

template inline void chkmax(T &x,T y) {if(x<y) x=y;}

int n; char s[maxn];

int main() { int T=read(); while(T--) { scanf("%s",s+1); n=strlen(s+1); int ans=INF; for(int i=0;i<=25;i++) { int res=0; for(int j=1;j<=n;j++) { int cha=s[j]-'a'-i; if(cha<0) cha=-cha; if(cha>13) cha=26-cha; res+=cha; } chkmin(ans,res); } printf("%d\n",ans); } return 0; }

完成一道C++编程题:n#-「MYOI-R1」幻想字符串nn##-题目背景nn!httpscdnluogucomcnuploadimage_hosting5unmwc5opngnn幻想的宇宙向世界敞开。nn小-M-来自幻想世界可能是过去现在亦或……将来?nn##-题目描述nn对于字符串-$s$每次选择其中的任意一个字符将其的-ASCII-码-$+1$-或-$-1$最终至少需要-$x$-次操作使得-$s$-的每一个字符均相同我们称-$x$-的值为-$s$-的幻想值。nn注:你必须保证在任意一次操作

原文地址: https://www.cveoy.top/t/topic/qa9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录