POJ 3094 Quicksum 水题

题意:A = 1, B = 2, C = 3, ····  Z = 26, ' ' = 0. 例如:
ACM: 1*1 + 2*3 + 3*13 = 46
MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
题解:

#include <iostream>
using namespace std;

int main()
{
	char str[256];
	while ( cin.getline(str,256,'\n') )
	{
		if ( str[0] == '#' ) break;
		long sum = 0;
		long len = strlen(str);
		for ( int i = 0; i < len; i++ )
		{
			if ( str[i] == ' ' ) continue;
			sum += ( str[i] - 'A' + 1 ) * ( i + 1 );   
		}
		cout << sum << endl;  
	}
	return 0;
}

你可能感兴趣的:(POJ 3094 Quicksum 水题)