#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char str[256];
int main(){
//scanf("%s",str);
gets(str);
while(strcmp(str,"#")!=0){
int sum=0;
int index=0;
for(; index <(int) strlen(str);index++){
if(isspace(str[index]))
continue;
sum+=(index+1)*(str[index]-'A'+1);
}
printf("%d\n",sum);
//scanf("%s",str);
gets(str);
}
return 0;
}
该程序通过C语言实现,读取用户输入的字符串并计算除空格外各字符的加权总和,每个字符按其在字符串中的位置进行加权。
239

被折叠的 条评论
为什么被折叠?



