【急救!】如何实现以下操作
字符串1: abcde字符串2: fghij
>>
字符串1: a1b1c1d1e
字符串2: f1g1h1i1j,a1b1c1d1e
本帖最后由 jackz007 于 2022-4-13 18:05 编辑
def foo1(s):
t = s
for i in range(1 , len(s)):
t = t + '1' + s
return t
def foo2(s1 , s2):
d =
d . sort()
return d
s1 , s2 = 'abcde' , 'fghij'
s1 , s2 = foo1(s1) , foo1(s2)
s2 = s1 + ',' + s2
print('s1 = ' , s1)
print('s2 = ' , s2)
print(* foo2(s1 , s2)) 本帖最后由 傻眼貓咪 于 2022-4-14 11:20 编辑
Pythona = "a1b1c1d1e"
b = "f1g1h1i1j,a1b1c1d1e"
print(f"共有{len(set(a) & set(b))}个字符相同:", *(set(a) & set(b)))
Javaimport java.util.Scanner;
public class Main {
public static void main(String[] args) {
int sum = 0;
boolean ASCII[] = new boolean;
String a = "a1b1c1d1e";
String b = "f1g1h1i1j,a1b1c1d1e";
char[] x = a.toCharArray();
char[] y = b.toCharArray();
for(char i: x){
for(char j: y){
if(i == j){
ASCII = true;
}
}
}
for(int i = 0; i < 256; i++){
if(ASCII){
char c = (char)i;
sum++;
System.out.println(c);
}
}
System.out.println("共有" + sum + "个字符相同");
}
}
页:
[1]