Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains
no more than 80 characters which are either English letters [A-Z] (case
insensitive), digital numbers [0-9], or "_" (representing the space). It is guaranteed that both strings are non-empty.
For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized.
Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.
7_This_is_a_test<br/>_hs_s_a_es
7TI
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String first=sc.next(); String second=sc.next(); first=first.toUpperCase(); second=second.toUpperCase(); for(int i=0;i<second.length();i++){ first=first.replace(second.charAt(i)+"",""); } String coutStr=""; for(int i=0;i<first.length();i++){ if(coutStr.contains(first.charAt(i)+"")){ continue; }else{ System.out.print(first.charAt(i)); coutStr+=first.charAt(i); } } System.out.println(); } }
public class Main {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
String originalString = input.nextLine();
String typedOutString = input.nextLine();
int[] keyboard = new int[128];
// 扫描已键入的字符串,将小写字母转换成大写字母,使用 ASCII 码与 keyboard 对应,将成功键入的字符位置为 1
for (int i = 0; i < typedOutString.length(); i++) {
char ch = Character.toUpperCase(typedOutString.charAt(i));
keyboard[ch] = 1;
}
// 扫描原始字符串,将小写字母转换成大小字母,去 keyboard 中检查是否已被成功键入,如果未成功键入,则打印对应的大写字母,
// 并将 keyboard 中的对应的字符位置为 -1,表明已被打印
for (int i = 0; i < originalString.length(); i++) {
char ch = Character.toUpperCase(originalString.charAt(i));
if (keyboard[ch] == 0) {
System.out.print(ch);
keyboard[ch] = -1;
}
}
input.close();
}
}
#include <string> #include <cstdio> #include <iostream> using namespace std; const int maxn = 26 + 10 + 1 + 5; int IF_Exit[maxn] = {0}; int Char2Id(char c){ if(c >= '0' && c <= '9') return (c - '0'); else if(c >= 'A' && c <= 'Z'){ return (c - 'A' + 10); } else if(c >= 'a' && c <= 'z'){ return (c - 'a' + 10); } else{ return 36; } } int main(){ string line1, line2; cin >> line1 >> line2; for(unsigned int i = 0; i<line2.size(); i++){ int id = Char2Id(line2[i]); if(!IF_Exit[id]) IF_Exit[id] = 1; } for(unsigned int i = 0; i<line1.size(); i++){ int id = Char2Id(line1[i]); if(!IF_Exit[id]){ IF_Exit[id] ++; if(id >= 0 && id <= 9){ printf("%d", id); } else if(id == 36){ printf("_"); } else if(id >= 10 && id <= 35){ char c = id - 10 + 'A'; printf("%c", c); } } } cout << endl; return 0; }
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<cctype> using namespace std; int main(){ string input,output; getline(cin,input); getline(cin,output); for(auto &c : input){ c = toupper(c); } for(auto &c : output){ c = toupper(c); } int b=0; string temp; for(int a=0;a<input.size();a++){ if(input[a]==output[b]){ b++; } else{ string::size_type pos = temp.find(input[a]); if(pos != temp.npos) continue; else { temp += input[a]; } } } for(auto c : temp){ cout << c; } return 0; }
//先把两个句子里面的所有小写的英文字母全部变成大写的 //然后以第一个句子从左向右遍历,第二个里面没有的都输出 //这里面有一个标记,可以去除重复的遍历,提升速度 //ctype.h头文件里包含着许多判断字符的函数,可以直接拿来用 #include <iostream> #include <string.h> #include <ctype.h> using namespace std; void sen_to_upper(char s[]) { int len = strlen(s), i = 0, j = 0; for (i = 0; i < len; i++) { if (islower(s[i])) { s[i] = toupper(s[i]); } } } int main() { int ans[128] = {0}, i = 0, j = 0, k = 0; char real[83], bre_out[83]; cin >> real; cin >> bre_out; sen_to_upper(real); sen_to_upper(bre_out); k = strlen(real); for (i = 0; i < k; i++) { if (ans[int(real[i])] == 1) continue; else { if (strchr(bre_out, real[i]) == NULL) { cout << real[i]; } ans[int(real[i])] = 1; } } return 0; }
a = input() res = '' if '<' in a: start = a.index('<') end = a.index('>') s1 = a[:start].upper() s2 = a[end+1:].upper() else: b = input() s1 = a.upper() s2 = b.upper() for c in s1: if c not in s2: if c not in res: res+=c print(res)
// 题目大概意思,键盘上有几个键坏了,为了找是哪几个,输入一串字符穿, // 如果输出结果中没有那个字符,就是那个坏了。 //输出要求:输出坏的键位,用大写表示 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String output = scanner.nextLine(); input = input.toUpperCase(); output = output.toUpperCase(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { String a = input.substring(i,i+1); if (!output.contains(a) && !sb.toString().contains(a)){ sb.append(a); } } String res = sb.toString(); System.out.println(res); } }
#include<iostream> (720)#include<vector> #include<string> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int isOk[128] = { 0 }; int isBroken[128] = { 0 }; for (int i = 0; i < s1.size(); i++) { if (isOk[s1[i]] || isBroken[s1[i]]) { continue; } bool flag = false; for (int j = 0; j <= i&&j<s2.size(); j++) { if ((s1[i] >= 'a' && s1[i] <= 'z') && (s1[i] == s2[j] || s1[i] == s2[j] - 'A' + 'a')) { isOk[s1[i]] = 1; isOk[s1[i] - 'a' + 'A'] = 1; flag = true; break; } else if ((s1[i] >= 'A' && s1[i] <= 'Z') && (s1[i] == s2[j] || s1[i] - 'A' + 'a' == s2[j])) { isOk[s1[i]] = 1; isOk[s1[i] - 'A' + 'a'] = 1; flag = true; break; } else if (s1[i] == s2[j]) {//空格和数字 isOk[s1[i]] = 1; flag = true; break; } } if (!flag) { isBroken[s1[i]] = 1; if (s1[i] >= 'a' && s1[i] <= 'z') { isBroken[s1[i] - 'a' + 'A'] = 1; printf("%c", s1[i] - 'a' + 'A'); } else if (s1[i] >= 'A' && s1[i] <= 'Z') { isBroken[s1[i] - 'A' + 'a'] = 1; printf("%c", s1[i]); } else { printf("%c", s1[i]); } } } }
import java.util.*; public class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); String a = sc.nextLine(); String b = sc.nextLine(); LinkedHashSet<Character> set = new LinkedHashSet<>(); for (int i = 0;i<a.length();i++){ if(!b.contains(String.valueOf(a.charAt(i)))){ if(a.charAt(i)>='a'&&a.charAt(i)<='z'){ char x = Character.toUpperCase(a.charAt(i)); set.add(x); }else { set.add(a.charAt(i)); } } } for(Character character: set){ System.out.print(character); } } }
#include<iostream> (720)#include<string> #include<set> using namespace std; set<char> outputSet; char toUpper(char c){ if (c >= 'a' && c <= 'z') return c + ('A' - 'a'); return c; } int main(){ string inStr, outStr; cin >> inStr >> outStr; for (int i = 0; i < outStr.size(); i++){ outputSet.insert(toUpper(outStr[i])); } for (int i = 0; i < inStr.size(); i++){ char tmp = toupper(inStr[i]); if (outputSet.find(tmp) == outputSet.end()){ outputSet.insert(tmp); cout << tmp; } } cout << endl; return 0; }
import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Scanner; /** * @auther zh * @data 2019/4/10 19:49 * 借鉴了其他人的明白题的意思,就是把两个字符串转大写, *然后不重复输出Str1中比Str2中的字符 */ public class Main { public static void main(String[] args) { //HashSet是为了去重 HashSet<Character> hashSet = new HashSet<>(); // LinkedHashSet是有序的set集合,按照添加进去的顺序输出 LinkedHashSet<Character> linkedHashSet = new LinkedHashSet<>(); StringBuilder sb =new StringBuilder(); Scanner sc = new Scanner(System.in); String str1 = sc.nextLine(); String str2 = sc.nextLine(); String res1 = str1.toUpperCase(); String res2 = str2.toUpperCase(); for (int i = 0; i < res2.length(); i++) { char c = res2.charAt(i); hashSet.add(c); } for (int i = 0; i < res1.length(); i++) { if (!hashSet.contains(res1.charAt(i))){ linkedHashSet.add(res1.charAt(i)); } } for (Character c : linkedHashSet){ System.out.print(c); } } }
//欢迎参观鄙人的博客https://blog.csdn.net/qq_33375598 #include<cstdio> #include<cstring> bool hashTable[128] = {false};//用来标记字符是否已被输出 const int maxn = 100; char str1[maxn], str2[maxn]; int main(int argc, char const *argv[]) { fgets(str1, maxn + 1, stdin); fgets(str2, maxn + 1, stdin); int len1 = strlen(str1) - 1;//获取长度 int len2 = strlen(str2) - 1; for (int i = 0; i < len1; ++i)//枚举第一个字符串每个字符 { int j; char c1, c2; for (j = 0; j < len2; ++j)//枚举第二个字符串每个字符 { c1 = str1[i]; c2 = str2[j]; if(c1 >= 'a' && c1 <= 'z') c1 -= 32;//小写字母转化为大写 if(c2 >= 'a' && c2 <= 'z') c2 -= 32; if(c1 == c2) break; } if(j == len2 && hashTable[c1] == false){//第二个字符串中未出现c1,且c1位被输出过 printf("%c", c1); hashTable[c1] = true; } } printf("\n"); return 0; }
#include <iostream> #include <set> using namespace std; int main() { set<char> output; const int MAX_N = 200; const int MAX_INPUT = 80; bool alphabet[MAX_N] = {false}; char target[MAX_INPUT] = {'*'}; char real[MAX_INPUT] = {'*'}; cin.getline(target, 80); cin.getline(real, 80); for(int i = 0; i < 80; i++) { if(target[i] >= 'a' && target[i] <= 'z') { target[i] = target[i] - 32; } if(real[i] >= 'a' && real[i] <= 'z') { real[i] = real[i] - 32; } } for(int i = 0; i < 80; i++) { if(real[i] != '*') { int index = (int)real[i]; alphabet[index] = true; } } for(int k = 0; k < 80; k++) { if(target[k] != '*') { int index = (int)target[k]; if(!alphabet[index]) { if(output.find(target[k]) == output.end()) { cout<<target[k]; } output.insert(target[k]); } } } cout<<endl; return 0; }
有没有大神解释一下为什么最后不去重不对
public static void main(String[] args)throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); StringBuffer first_String=new StringBuffer(reader.readLine().toUpperCase()); StringBuffer temp=new StringBuffer(reader.readLine().toUpperCase()); cud(temp); cud(first_String); for(int j=0;j<first_String.length();j++) { for (int i = 0; i < temp.length(); i++) { if(temp.charAt(i)==first_String.charAt(j)) { first_String.delete(j,j+1); } } } for(int i=0;i<5;i++) { cud(first_String); } System.out.println(first_String.toString().toUpperCase()); } public static void cud(StringBuffer temp) { for(int j=0;j<temp.length();j++) { for (int i = j+1; i < temp.length(); i++) { if(temp.charAt(i)==temp.charAt(j)) { temp.delete(i,i+1); } } } }
}