您的位置:首页 > 其它

Section 1.2.3 Name That Number 水

2015-07-08 22:42 435 查看
题意: http://www.wzoi.org/usaco/11%5C206.asp

解法:

  貌似解法是多种多样的

  我的方法是,将字典里所有字母转为数字,然后检查是不是和输入相同

  patpat

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll trans(string name){
int len = name.length(), i;
ll val = 0ll;
for(i = 0; i < len; i++){
if(name[i] < 'Q')val = val * 10 + (name[i] - 'A')/ 3 + 2;
else {
val = val * 10 + (name[i] - 'A' - 1) / 3 + 2;
}
}
return val;

}
int main()
{
ifstream fin("namenum.in");
ifstream dict("dict.txt");
#ifndef poi
ofstream fout("namenum.out");

#endif

ll inp;
fin >> inp;
string name;
bool gg = true;

while(dict>>name){
// cout<< name <<" "<<trans(name) <<endl;
if(inp != trans(name))  continue;

gg = false;
fout<<name<<endl;
}
if(gg)  fout<<"NONE"<<endl;

dict.close();;
fin.close();

#ifndef poi
fout.close();

#endif
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: