注意_和某个阿拉伯数字的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;
}
转载须注明出处。