Section 1.2.3 Name That Number 水
题意: http://www.wzoi.org/usaco/11%5C206.asp
解法:
貌似解法是多种多样的
我的方法是,将字典里所有字母转为数字,然后检查是不是和输入相同
patpat
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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; }