#include <stdio.h>
#include<string.h>
char a[100000];
int main() {
int t,s,i,j,len;
scanf("%d",&t);
for(i=0;i<t;i++){
s=0;
scanf("%s",a);
len=strlen(a);
for(j=0;j<len;j++){
s+=a[j]-64;
}
printf("%d\n",s);
}
return 0;
}
觉得有用的话采纳一下哈
解决思路:
1、声明用于存放获取几行数据的变量t,获取字符输入的变量ch,一个数组下标变量i
2、从输入获取一个整数,并存入到变量t
3、声明一个用于存放几条手链价格的变量prices,数组大小为前面获取的变量t
4、初始化prices数组
6、用getchar清除前面的输入
7、用一个循环获取t行手链的数据,数据存放到prices数组
8、打印所有手链的价格prices
int main(){
int t;
char ch;
scanf("%d",&t);
int prices[t];
int i;
for(i=0;i<t;i++){
prices[i]=0;
}
while(getchar()!='\n')
;
i = 0;
while(i<t){
while((ch=getchar())!='\n'){
prices[i]+=ch-'A'+1;
}
i++;
}
i=0;
while(i<t){
printf("%d\n",prices[i++]);
}
}