第一题没想到n4都能过
package kedaxunfei; import java.util.Scanner; public class bishi01 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); int m=scanner.nextInt(); int n=scanner.nextInt(); int nums[][]=new int[m][n]; for (int i=0;i<m; i++) for(int j=0;j<n;j++) nums[i][j]=scanner.nextInt(); int max=0; for(int i=0;i<nums.length;i++) { for(int j=0;j<nums[0].length;j++) { int first=nums[i][j]; for(int k=0;k<m;k++) { for(int l=0;l<n;l++) { if(k==i || l==j) continue; else { int tem=first*nums[k][l]; max=Math.max(tem, max); } } } } } System.out.println(max); } }
第二题我直接用了自带的排序
package kedaxunfei; import java.util.Arrays; import java.util.Scanner; public class bishi02 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int nums[]=new int[n]; for(int i=0;i<n;i++) { nums[i]=scanner.nextInt(); } Arrays.sort(nums); for(int i=0;i<n;i++) System.out.print(nums[i]+" "); } }
第三题用bigInteger的bitcount函数就可
package kedaxunfei; import java.math.BigInteger; import java.util.Scanner; public class bishi03 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); long n=scanner.nextLong(); BigInteger bigInteger=BigInteger.valueOf(n); int ans=bigInteger.bitCount(); System.out.println(ans); } }
第四题注意取模,我开始因为如果长了是不变,发现取模就直接过了
package kedaxunfei; import java.util.Scanner; public class bishi04 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); String string=scanner.nextLine(); int n=scanner.nextInt(); n=n%string.length(); String a1=string.substring(0,n); String a2=string.substring(n,string.length()); StringBuffer anStringBuffer=new StringBuffer(); anStringBuffer.append(a2); anStringBuffer.append(a1); System.out.println(anStringBuffer.toString()); } }
全部评论
(1) 回帖