section1.2.3

这道题还是可以说是比较简单的,一开始是准备将输入的数字转换的名称全部保存下来,再将这些名称在字典中查找,毫无疑问,这样子太麻烦了,于是就换了一种思路,将字典的名称转换成数字与输入的数字比较,其中还需要注意一层层的筛选。代码如下。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int namesearch(char c){
	int x=c-'A';
	if (x>'Q'-'A'){
		x--;
	}
	int num=(x/3)+2;
	return num;
}
int main (){
	freopen ("namenum.in","r",stdin);
	string s;
	cin>>s;
	int l=s.length();
	int i=0,cnt=0;
	char ss[20],dic[5000][20];
	bool judge=true,flag=false;
	string dict;
	freopen ("dict.txt","r",stdin);
	freopen ("dict.out","w",stdout);
	while(scanf("%s",ss)!=EOF){
		dict=ss;
		if (dict.length()!=l){
			continue;
		}
		else {
			judge=true;
			for (i=0;i<l;i++){
				if (namesearch(dict[i])!=(s[i]-'0')){
					judge=false;
				}
			}
			if (judge){
				cout<<dict<<endl;
				flag=true;
			}
		}
	}
	if (!flag){
		cout<<"NONE";
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值