USACO-1.2.3 Name That Number

题目链接:http://cerberus.delos.com:790/usacoprob2?a=Emp6KiAXNKv&S=namenum

一看到这个题目就想到了map和mutimap。刚好可以学习一下容器。但是不知道为什么就一直错。后来才看到原来是数据坑爹了,这个数据太坑爹了。仔细看才发现它的字母表里面没有Q,导致我前面一直错。后来改过来就对了。

/*
ID:sunexio2
PROG:namenum
LANG:C++
 */
#include 
#include 
#include 
#include 
#include 
using namespace std;

map m;
multimap mm;
int main(){
	char c = 'A';
	for(char i = 2; i <= 6; ++i, c += 3)
		m[c] = m[c + 1] = m[c + 2] = i;
	m['P'] = m['R'] = m['S'] = 7;
	m['T'] = m['U'] = m['V'] = 8;
	m['W'] = m['X'] = m['Y'] = 9;
	//m['z'] = '0';
	ifstream tin("dict.txt");
	string str;
	while(tin >> str){
		double d = 0;
		for(int i = 0; i < str.length(); ++i)
			d = d * 10 + m[str[i]];
		mm.insert(pair(d, str));
	}
	//fin.close();
	ifstream fin("namenum.in");
	ofstream fout("namenum.out");
    double tmp;
	while(fin >> tmp){
		multimap::iterator it;
		bool flag = 1;
		for(it = mm.begin(); it != mm.end(); ++it)
		{
			if(abs(it->first - tmp) <= 0)
			{
				fout << it->second << endl;
				flag = 0;
			}
		}
		if(flag) fout << "NONE" << endl;
	}
	return 0;
}


你可能感兴趣的:(acm)