爱奇艺三道编程题50%0%40% 求教大神帮我看看哪里有问题
求各位AC的大神帮我看一看!万分感谢! 1.求重复序列后两个序列是否相等
public static void main(String[] args) {
Scanner in = new Scanner(System.in);long x1 = in.nextInt();
int k1 = in.nextInt();
long x2 = in.nextInt();
int k2 = in.nextInt();
long v1 =getReal(x1,k1);
long v2 =getReal(x2,k2);
System.out.println(v1);
System.out.println(v2);
if(v1==v2){
System.out.println("Equal");
}
else if(v1<v2){
System.out.println("Less");
}
if(v1>v2){
System.out.println("Greater");
}
}
public static long getReal(long num,int k){
String str =String.valueOf(num);
String out ="";
for(int i=1;i<=k;i++){
out=out+str;
}
return Long.valueOf(out);
}
2.求括号的深度
public class main1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String [] ss =s.split("");
int result =getDeep(ss);
System.out.println(result);
}
public static int getDeep(String [] s){
int flagnum=0;
int max =0;
if(s[0].equals("")){
return 0;
}
for(int i=0;i<s.length;i++){
if(s[i].equals("(")){
flagnum++;
}
else if(s[i].equals(")")){
max=Math.max(max,flagnum);
flagnum=flagnum-1;
}
}
return max;
}
}
3.求平方个和的平方问题
public class main1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String [] ss =s.split("");
int result =getDeep(ss);
System.out.println(result);
}
public static int getDeep(String [] s){
int flagnum=0;
int max =0;
if(s[0].equals("")){
return 0;
}
for(int i=0;i<s.length;i++){
if(s[i].equals("(")){
flagnum++;
}
else if(s[i].equals(")")){
max=Math.max(max,flagnum);
flagnum=flagnum-1;
}
}
return max;
}
}
3.求平方个和的平方问题
import java.util.Scanner;
public class main2 {
public static int num=0;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {//注意while处理多个case
long n = in.nextInt();
long m = in.nextInt();
boolean flag=false;
Double d=0.00;
for(long i=1;i<=(n<=m?n:m);i++){
for(long j=(n<=m?n:m)+1;j<=(n<m?m:n);j++){
Double d1=Math.sqrt(i);
Double d2=Math.sqrt(j);
d=Math.pow(d1+d2,2);
if((d*10)%10==0){
num++;
System.out.println("i:"+i+"j:"+j);
}
else if(((d2/d1)*10)%10==0){
num++;
System.out.println("i:"+i+"j:"+j);
}
}
}
System.out.println(num+(n<=m?n:m));
}
}
}
public class main2 {
public static int num=0;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {//注意while处理多个case
long n = in.nextInt();
long m = in.nextInt();
boolean flag=false;
Double d=0.00;
for(long i=1;i<=(n<=m?n:m);i++){
for(long j=(n<=m?n:m)+1;j<=(n<m?m:n);j++){
Double d1=Math.sqrt(i);
Double d2=Math.sqrt(j);
d=Math.pow(d1+d2,2);
if((d*10)%10==0){
num++;
System.out.println("i:"+i+"j:"+j);
}
else if(((d2/d1)*10)%10==0){
num++;
System.out.println("i:"+i+"j:"+j);
}
}
}
System.out.println(num+(n<=m?n:m));
}
}
}