pat 乙级 c++ 旧键盘 (20分)

注意_和某个阿拉伯数字的ascii码差值等于大小写字母之间的差值。

#include <cstdio>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;

int hashtable[38]={0};

int main(){
	string str1, str2;
	cin >> str1 >> str2;
	int index=0,mark=0;
	for(string::iterator it1=str1.begin(); it1!=str1.end(); it1++){
		if(*it1>='a'&&*it1<='z') *it1=*it1-'a'+'A';
	}
	for(string::iterator it2=str2.begin(); it2!=str2.end(); it2++){
		if(*it2>='a'&&*it2 <= 'z') *it2=*it2-'a'+'A';
	}	
	string::iterator it2=str2.begin();
	for(string::iterator it1=str1.begin(); it1!=str1.end(); it1++){
		if(*it1>='0'&&*it1<='9') index=26+*it1-'0';
		else if(*it1>='A'&&*it1<='Z') index=*it1-'A';
		else index=37;
		mark = 1;
		for(string::iterator it2=str2.begin(); it2!=str2.end(); it2++){	
			if(*it1==*it2 ) {		
//本来我用的是这样的判断(*it1==*it2 || *it1==*it2-'a'+'A') ,*it2没有转为大写。
//看了ascii码后发现_和某个阿拉伯数字 的位置差值 恰好和大小写差值相同,所以这样写是行不通的。
				mark=0;
				break;				
			}
			/*if((*it1==*it2 || *it1==*it2-'a'+'A') && hashtable[index]==0){
				printf("%c",*it1);
				hashtable[index]==1;;
				break;
			} */
		}
		if(mark && hashtable[index]==0){
			printf("%c",*it1);
			hashtable[index]=1;			
		}
	}  
	return 0;
}

转载须注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值