Bootstrap

杭电OJ | 2734 Quicksum 用gets输入

2734

Problem Description

ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650

Input             The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

Output           For each packet, output its Quicksum on a separate line in the output.

Sample Input

ACM

MID CENTRAL

#

Sample Output

46

650

要点

gets(input) && input!=NULL && input[0]!='#'  //以#结尾要记得这么写!
#include <stdio.h>
#include <string.h>
int main(){
	char input[255];
	while(gets(input)&&input!=NULL&&input[0]!='#'){
		int i;
		int sum = 0;
		for(i=0;i<strlen(input);i++){
			int nownum;
			if(input[i]==' '){
				nownum = 0;
			}
			else{
				nownum = input[i]-'A'+1;
			}
			sum = sum + nownum*(i+1);
		}
		printf("%d\n",sum);
	}
        return 0;
}

 

;