usaco_namenum

本文介绍了一个使用 C++ 编写的程序,该程序能够将电话按键输入转换为可能对应的人名。通过读取电话号码文件并对照字典文件,程序找出符合电话按键组合的所有人名。如果未找到匹配项,则输出 'NONE'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/* ID:mingcha1 PROG: namenum LANG: C++ */ #include<iostream> #include<string> #include<fstream> #include<vector> using namespace std; ifstream fin("namenum.in"); ofstream fout("namenum.out"); //#define DEBUG #ifdef DEBUG #define in cin #define out cout #else #define in fin #define out fout #endif void solve(){ int map[] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1}; string num; in>>num; int len=num.size(); fstream dict_in("dict.txt"); vector<string > dict; string tmp; while(dict_in>>tmp){ if(tmp.size()==len) dict.push_back(tmp); } len=dict.size(); bool flag2=true; for(int i=0;i<len;++i){ int flag1=true; for(int j=0;j<dict[i].size();++j){ if(map[dict[i][j]-'A']!=num[j]-'0'){ flag1=false; break; } } if(flag1==true){ out<<dict[i]<<endl; flag2=false; } } if(flag2==true) out<<"NONE"<<endl; } int main(){ solve(); return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值