sicily 1388

#include "iostream"
#include "map"
#include "string"
using namespace std;
int main()
{
	map<char, int> m;//定义一个map容器
	m[' '] = 0; m['A'] = 1; m['B'] = 2; m['C'] = 3; m['D'] = 4; m['E'] = 5; m['F'] = 6; m['G'] = 7; m['H'] = 8; m['I'] = 9; m['J'] = 10;
	m['K'] = 11; m['L'] = 12; m['M'] = 13; m['N'] = 14; m['O'] = 15; m['P'] = 16; m['Q'] = 17; m['R'] = 18; m['S'] = 19; m['T'] = 20;
	m['U'] = 21; m['V'] = 22; m['W'] = 23; m['X'] = 24; m['Y'] = 25; m['Z'] = 26; 
	map<char, int>::iterator it;//定义一个迭代器,遍历容器所用!
	string str;
	getline(cin, str);
	while (str != "#")
	{
		int length = str.size();
		int sum = 0;
		for (int i = 0; i < length; i++)
			for (it = m.begin(); it != m.end(); it++)
			{
				if ((*it).first == str[i])//寻找匹配的字母
				{
					sum += (*it).second * (i+1);
					continue;
				}
			}
		cout << sum << endl;
		getline(cin, str);
	}
}

 

你可能感兴趣的:(c,String,iterator,include)