//本题示例输入和实际输入不符。 //按照示例输入的话应该是两个字符串位于同一行。 //这样在处理输入的方法上有差别,这点需要注意! #include<iostream> #include<string> using namespace std; int main() { string line; string str; string s; //getline(cin, line); //cout << line <<endl; /*for(int i = 0; i < line.size(); i++) { if(line[i] == '.') { str = line.substr(0, i); s = line.substr(i+1, line.size()-i-1); break; } }*/ getline(cin, str); getline(cin, s); string ret; for(int i = 0; i < str.size(); ++i) { if(s.find(str[i]) == string::npos) { ret = ret + str[i]; } } cout << ret << endl; }
//用javascript function delectAfromB(sA,sB){ var arrA = sA.split(""); var arrB = sB.split(""); for(var i=0; i<arrB.length; i++){ for(var j=0; j<arrA.length; j++){ if(arrB[i]===arrA[j]){ arrA.splice(j,1); } } } return arrA.join(""); } //for test var a="They are students."; var b="aeiou"; console.log(delectAfromB(a,b));//Thy r stdnts.
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String act=scanner.nextLine(); String del=scanner.next(); Set<Character> delstr=new HashSet<>(); for (int i=0;i<del.length();i++) { delstr.add(del.charAt(i)); } for (int i=0;i<act.length();i++) { char c=act.charAt(i); if (!delstr.contains(c)) { System.out.print(c); } } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); Set<Character> hash = new HashSet<>(); String str1 = in.nextLine(); String str2 = in.nextLine(); for (int i = 0; i < str2.length(); i++) { hash.add(str2.charAt(i)); } StringBuffer ret = new StringBuffer(); for (int j = 0; j < str1.length(); j++) { char n = str1.charAt(j); if (!hash.contains(n)){ ret.append(n); } } System.out.println(ret); } }
import java.util.Scanner; //笨人的解题思路,如有不对,敬请谅解phone:18845636132 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str1 = in.nextLine(); String str2 = in.nextLine(); //有空格,空格到‘z’的距离90 int[] strs = new int[90]; //获得较小的字符串数组 char[] temp0 = (str1.length()>=str2.length()?str2:str1).toCharArray(); //存在加1 for(char s:temp0) { strs[s-32]++; } String result = ""; //获得较大数组 char[] temp1 = (str1.length()>str2.length()?str1:str2).toCharArray(); for(char s: temp1) { //如果strs对应位数为零,则将该数加入到结果中 if(strs[s-32]==0) { result = result+s; } } System.out.println(result); } }
import java.util.*;
public class Main {
/*
* 删除公共字符
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String s2 = sc.nextLine();
String[] ss = s.split(" ");
String[] s1 = new String[ss.length];
String res = "";
for(int i=0;i<ss.length;i++){
s1[i] = ss[i];
}
//得到了一个目标字符串数组s1 和一个字符串s2
for(int i=0;i<s1.length;i++){
char[] r = s2.toCharArray();
for(int j=0;j<r.length;j++){
if(s1[i].contains(String.valueOf(r[j]))){
s1[i] = s1[i].replace(r[j], ' ');
}
s1[i]=s1[i].trim();
s1[i]=s1[i].replace(" ", "");
}
}
for (String string : s1) {
res+=string+" ";
}
System.out.println(res);
}
}
// 直接去掉在第二个字符串里面的字符就行,为了快速查找,直接用了set的数据结构 import java.util.Scanner; import java.util.HashSet; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); HashSet set = new HashSet<Character>(); while(sc.hasNext()){ String str1 = sc.nextLine(); String str2 = sc.nextLine(); for(int i=0;i<str2.length();i++){ set.add(str2.charAt(i)); } StringBuilder sb = new StringBuilder(); for(int i=0;i<str1.length();i++){ if(!set.contains(str1.charAt(i))){ sb.append(str1.charAt(i)); } } System.out.println(sb.toString()); set.clear(); } } }
#include <iostream> #include <string> using namespace std; int main() { string str1, str2; getline(cin, str1); getline(cin, str2); for (int i = 0;i < str1.size();++i) for (int j = 0;j < str2.size();++j) { if (str1[i] == str2[j]) { str1.erase(i, 1); i -= 1; break; } } cout << str1 << endl; return 0; }
import java.util.Scanner; /** * Created by Administrator on 2017/9/3. */ public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); String str=in.nextLine(); int[] a=new int[256]; char[] ch=in.nextLine().toCharArray(); for(int i=0;i<ch.length;i++){ a[ch[i]]=1; } for(int i=0;i<str.length();i++){ if(a[str.charAt(i)] != 1){ System.out.print(str.charAt(i)); } } } }
#include <iostream> #include <vector> #include <string> using namespace std; void delet(string &s, string &s_base) { for (int i = 0; i<s.size(); ++i) { for (int j = 0; j<s_base.size(); ++j) { if (s[i] == s_base[j]) s.erase(i, 1); } } } int main() { string str, s_ba; vector<string> svec; while (cin >> str) { svec.push_back(str); if (getchar() == '\n') break; } cin >> s_ba; for (int i = 0; i<svec.size(); ++i) delet(svec[i], s_ba); for (vector<string>::iterator iter = svec.begin(); iter != svec.end(); ++iter) { cout << *iter; if (iter != svec.end() - 1) cout << " "; else cout << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { string s1,s2; getline(cin,s1); getline(cin,s2); int a[256]={0}; for(int i=0;i<s2.size();i++) a[s2[i]]++; for(int i=0;i<s1.size();i++) { if(a[s1[i]]) continue; cout<<s1[i]; } cout<<endl; return 0; }
#include<iostream> #include<string> using namespace std; int main() { string s1,s2; while(getline(cin,s1)&&getline(cin,s2)) { // getline(cin,s2); //一定要注意含空格的字符串不能直接用cin输入 int len1=s1.length(); //应该用getline int len2=s2.length(); for(int i=0;i<len2;i++) { for(int j=0;j<len1;j++) { if(s1[j]==s2[i]) //对于s2中每个字符串,依次遍历s1,若有相同的 { //将其后面所有的字符串向前移动一位,覆盖 for(int k=j;k<len1;k++) s1[k]=s1[k+1]; } } } cout<<s1<<endl; } }