网易笔试题1,2,4代码
第4题:这么写的但是通过为0;干!
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String str=sc.nextLine();
String string=sc.nextLine();
String str1=str.replace('0', 'q');
str1=str1.replace('1', '0');
str1=str.replace('q', '1').replaceAll("^(0+)", "");
string= string.replaceAll(str,"");
string= string.replaceAll(str1,"");
if (string.equals(""))
System.out.println("YES");
else
System.out.println("NO");
}
}
知道这么做了,附上正确代码:
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String str=sc.nextLine();
String string=sc.nextLine();
String str1=str.replace('0', 'q');
str1=str1.replace('1', '0');
str1=str.replace('q', '1').replaceAll("^(0+)", "");
string= string.replaceAll(str,"");
string= string.replaceAll(str1,"");
if (string.equals(""))
System.out.println("YES");
else
System.out.println("NO");
}
}
知道这么做了,附上正确代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String str=sc.nextLine();
String string=sc.nextLine();
string= string.replaceAll(str,"");
while(!str.equals(""))
{
String str1=str.replace('0', 'q');
str1=str1.replace('1', '0');
str1=str.replace('q', '1').replaceAll("^(0+)", "");
string= string.replaceAll(str1,"");
str=str1;
}
if (string.equals(""))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
#网易##笔试题目#public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String str=sc.nextLine();
String string=sc.nextLine();
string= string.replaceAll(str,"");
while(!str.equals(""))
{
String str1=str.replace('0', 'q');
str1=str1.replace('1', '0');
str1=str.replace('q', '1').replaceAll("^(0+)", "");
string= string.replaceAll(str1,"");
str=str1;
}
if (string.equals(""))
System.out.println("YES");
else
System.out.println("NO");
}
}
}