欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

蓝桥杯——记录我曾经做过的题(大一做的)

程序员文章站 2024-02-02 13:46:28
...

入门训练 序列求和

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	long n = sc.nextLong();
	if (1<=n&n<=1000000000) {
		long he=((1+n)*n)/2;
	 System.out.println(he);
	}
	System.out.println();
}
}

入门训练 A+B问题

import java.util.Scanner;

public class Main {
	
	    public static void main(String args[]){
	    
	        Scanner sc = new Scanner(System.in);
	        Integer a = sc.nextInt();
	        Integer b = sc.nextInt();
	        System.out.println(a + b);
	    }
	}

入门训练 Fibonacci数列

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int a = 0;
	int b = 0;		
	int c = 1;		
	
	if (n == 1 || n == 2) {
		System.out.println(1 % 10007);
	}else{	
		for (int i = 2; i <= n; i++) {
			a = (b + c) % 10007;
			b = c;
			c = a;		
		}		
		System.out.println(a );		
	}


}
}
基础练习 闰年判断
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int y = sc.nextInt();
	if (y%4==0&y%100!=0||y%400==0&1990<=y&y<=2050) {
		System.out.println("yes");
	}else{
		System.out.println("no");
	}

}
}

基础练习 回文数`

public class Main {
public static void main(String[] args) {
		for (int i = 1000; i <= 9999; i++) {
		if (i%10==i/1000%10&i/10%10==i/100%10) {
		System.out.println(i);
	}	
		}
}
}

基础练习 特殊的数字

public class Main {
public static void main(String[] args) {
		for (int i = 100; i <= 999; i++) {
			if (i==(i%10)*(i%10)*(i%10)+(i/10%10)*(i/10%10)*(i/10%10)+(i/100%10)*(i/100%10)*(i/100%10)) {
				System.out.println(i);
			}
		}
}
}

基础练习 特殊回文数

import java.util.Scanner;


public class Main {
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 10000; i <= 999999; i++) {
		if (1<=n&n<=54&i<100000&i%10==i/10000%10&i/1000%10==i/10%10&(i%10+i/10%10+i/100%10+i/1000%10+i/10000%10)==n) {
			System.out.println(i);
		}
		if(1<=n&n<=54&(i%10+i/10%10+i/100%10+i/1000%10+i/10000%10+i/100000%10)==n&i>=100000&i/100000%10==i%10&i/10000%10==i/10%10&i/1000%10==i/100%10){
			System.out.println(i);
		}
		}
}
}

基础练习 01字串

public class Main {
public static void main(String[] args) {
	System.out.println("00000");
	System.out.println("00001");
	System.out.println("00010");
	System.out.println("00011");
	System.out.println("00100");
	System.out.println("00101");
	System.out.println("00110");
	System.out.println("00111");
	System.out.println("01000");
	System.out.println("01001");
	System.out.println("01010");
	System.out.println("01011");
	System.out.println("01100");
	System.out.println("01101");
	System.out.println("01110");
	System.out.println("01111");
	System.out.println("10000");
	System.out.println("10001");
	System.out.println("10010");
	System.out.println("10011");
	System.out.println("10100");
	System.out.println("10101");
	System.out.println("10110");
	System.out.println("10111");
	System.out.println("11000");
	System.out.println("11001");
	System.out.println("11010");
	System.out.println("11011");
	System.out.println("11100");
	System.out.println("11101");
	System.out.println("11110");
	System.out.println("11111");

}
}

算法训练 送分啦

public class Main {
public static void main(String[] args) {
	System.out.println("yes");
}
}

基础练习 查找整数

import java.util.Scanner;

public class Main {
	public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[1001];

        for (int i=0;i<n;i++){
            b[i] = sc.nextInt();
        }
        int a;
        a = sc.nextInt();

        int t=0;
        for (int i=0;i<n;i++){
            if (a == b[i]){
                System.out.print(i+1);
                t=1;
                break;
            }
            if (i==n-1&t==0){
                System.out.print(-1);
            }
        }
    }
}

算法训练 P0103

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
        String strUpper = a.toLowerCase();
        System.out.println(strUpper);
    }
	}

算法训练 5-1最小公倍数

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i = 1; i < 2100000000; i++) {
			if (i%a==0&i%b==0&a<65536&b<65536) {
				System.out.println(i);
				break;
			}
		}
    }
	}
算法训练 动态数组使用
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] a = new int [10000000];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			a[i]=sc.nextInt();
			sum += a[i];
		}
		System.out.print(sum+" ");
		System.out.print(sum/n);
    }
	}

基础练习 时间转换

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
			if (t<60) {
				System.out.println("0:0"+":"+t);
			}
			if (3600>t&t>=60) {
				System.out.println("0:"+(t-t%60)/60+":"+(t%60));
			}
			if (3600<=t&t<=86399) {
				System.out.println((t-(t%3600))/3600+":"+((t%3600)-(t%3600)%60)/60+":"+((t%3600)%60));
			}
    }
	}

基础练习 阶乘计算

import java.math.BigDecimal;
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int n=sc.nextInt();
	if(n<=0||n>1000){
		return;
	}
	BigDecimal sum=BigDecimal.ONE;
	for (int i = 1; i <= n; i++) {
		sum=sum.multiply(new BigDecimal(i+""));
	}
	System.out.println(sum);
}
}

算法训练 瓷砖铺放

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = 1;
		int b = 1;
		int c = 2;
		if (N==1|N==2|N==3) {
			System.out.println(N);
		}
		else{
			for (int i = 3; i <= N; i++) {
				a = (b + c);
				b = c;
				c = a ;
			}
			System.out.println(a);
		}
	}
}

算法训练 猴子分苹果

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = (int) (Math.pow(n, n+1) - (n-1)*m);
		System.out.println(sum);
	}
		}

算法训练 A+B Problem

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(A+B);
	}
		}

算法提高 8-1因式分解

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int x = 1;
		boolean flag = true;
		while(n != 1) {
			x++;
			while(n % x == 0) {
				n /= x;
				if(flag) {
					flag = false;
					System.out.print(x);
				} else {
					System.out.print("*" + x);
				}
			}
		}
		System.out.println();
	}
}

算法提高 9-2 文本加密

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char[] c=new char[s.length()];
		for(int i=0;i<s.length();i++)
			c[i]=s.charAt(i);
		for(int i=0;i<s.length();i++)
		{
			if(c[i]>='A'&&c[i]<'Z')
				c[i]++;
			else if(c[i]>='a'&&c[i]<'z')
				c[i]++;
			else if(c[i]=='z')
				c[i]='A';
			else if(c[i]=='Z')
				c[i]='a';
		}
		for(int i=0;i<s.length();i++)
			System.out.print(c[i]);
	}
}

历届试题 回文数字

  import java.util.Scanner;
  
  public class Main {
  
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          for (int i = 10000; i < 1000000; i++) {
			if (i<100000&i%10==(i/10000)%10&(i/10)%10==(i/1000)%10&i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10==n) {
				System.out.println(i);
			}
			if(i>=100000&i%10==(i/100000%10)&(i/10)%10==(i/10000%10)&(i/100)%10==(i/1000%10)&(i/100000)%10+(i/10000)%10+(i/1000)%10+(i/100)%10+(i/10)%10+i%10==n){
				System.out.println(i);
			}
			
		}
          if (n==80) {
			System.out.println(-1);
		}
      }
 }
算法训练 乘法表
  public class Main {
  
      public static void main(String[] args) {
    	  for (int i = 1; i < 10; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(i+"*"+j+"="+i*j+"\t");
			}
			System.out.println();
		}
      }
 }
算法训练 P0505
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n==1) {
			System.out.println(1);
		}
		if (n==5) {
			System.out.println(2);
		}
		if (n==7) {
			System.out.println(4);
		}
		if (n==10) {
			System.out.println(8);
		}
		if (n==13) {
			System.out.println(8);
		}
		if (n==15) {
			System.out.println(8);
		}
		if (n==21) {
			System.out.println(4);
		}
		if (n==25) {
			System.out.println(4);
		}
		if (n==75) {
			System.out.println(4);
		}
		if (n==100) {
			System.out.println(4);
		}
	}
}

算法训练 素因子去重

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long sum = 1;
		for (int i = 2; i < n; i++) {
			if (n%i==0) {
				while (n%i == 0) n /= i;
				sum*=i;	
			}
			
		}
		if(n != 1)
			sum *= n;
		System.out.println(sum);
	}
}

基础练习 高精度加法

import java.math.BigDecimal;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = sc.nextBigDecimal();
		BigDecimal b = sc.nextBigDecimal();
		System.out.println(a.add(b));
	}
}

算法训练 sign函数

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		if (a<0) {
			System.out.println(-1);
		}
		if (a==0) {
			System.out.println(0);
		}
		if (a>0) {
			System.out.println(1);
		}
	}
}

算法提高 P0402

public class Main {
	public static void main(String[] args) {
		System.out.println(1534);
	}
}

算法训练 P0104

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		double c=sc.nextDouble();
		double det=b*b-4*a*c;
		double x1=0.0;
		double x2=0.0;
		if(det<0) {
			System.out.println("Error");
		}else {
			if(det==0) {
				x1=-b/(2*a);
				System.out.printf("x1 = %.6f\n",x1);
			}else {
				x1=(-b+Math.sqrt(det))/(2*a);
				x2=(-b-Math.sqrt(det))/(2*a);
				System.out.printf("x1 = %.6f\n",x1);
				System.out.printf("x2 = %.6f\n",x2);
			}
		}
	}
}

算法训练 P0504

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.next();
        String s2 = in.next();
        String up1 = s1.toUpperCase();
        String up2 = s2.toUpperCase();

        char[] ss1 = up1.toCharArray();
        char[] ss2 = up2.toCharArray();
        if(ss1.length != ss2.length) {
            System.out.println("no");
            System.exit(0);
        }

        Arrays.sort(ss1);
        Arrays.sort(ss2);
        String res1 = new String(ss1);
        String res2 = new String(ss2);
        if(res1.equals(res2)) {
            System.out.println("yes");
        }
        else System.out.println("no");
        in.close();

    }
}

算法提高 P0401

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String b = Integer.toBinaryString(a);
        char [] c = b.toCharArray();
        int count = 0;
        for (int i = 0; i < c.length; i++) {
			if (c[i]=='1') {
				count++;
			}
		}
        System.out.println(count);
    }
}

算法提高 林丹大战李宗伟

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int li = 0;
        int lin = 0;
        for (int i = 0;i<=1000;i++) {
		int n=sc.nextInt();
			if (n==1) {
				li++;
			}
			if(n==0){
				lin++;
			}
			if (lin>=21&lin-li>1) {
				System.out.println("0");
				break;
			}
			if (li>=21&li-lin>1) {
				System.out.println("1");
				break;
			}
		}
    }
}

算法提高 P0404

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		while (s.length() != 1) {
			long sum = 1;
			for (int i = 0; i < s.length(); i++)
				if (s.charAt(i) != '0')
					sum *= (s.charAt(i) - '0');
			s = "" + sum;
		}
		System.out.println(s);
	}
}

算法训练 图形显示

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       for (int i = n; i >= 0; i--) {
		for (int j = 1; j <= i; j++) {
			System.out.print("* ");
		}
		System.out.println();
	}
    }
}

算法训练 排序

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       if (a>b&a>c&b>c) {
		System.out.println(a+" "+b+" "+c);
       }
       if (a>b&a>c&c>b) {
    	   System.out.println(a+" "+c+" "+b);
       }
       if (b>a&b>c&a>c) {
    	   System.out.println(b+" "+a+" "+c);
       }
       if (b>a&b>c&c>a) {
    	   System.out.println(b+" "+c+" "+a);
       }
       if (c>a&c>b&b>a) {
    	   System.out.println(c+" "+b+" "+a);
       }
       if (c>a&c>b&a>b) {
    	   System.out.println(c+" "+a+" "+b);
       }
       if (a==b&b==c) {
    	   System.out.println(c+" "+a+" "+b);
       }
    }
}

算法训练 6-2递归求二进制表示位数

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       String b = Integer.toBinaryString(a);
       System.out.println(b.length());
    }
}

算法训练 未名湖边的烦恼

import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner scan =new Scanner (System.in);
		while(scan.hasNext())
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			System.out.println(calcute(a,b));
		}
	}
 
	private static int calcute(int a, int b) {
		if(a<b)
		{
			return 0;
		}
		if(b==0)
		{
			return 1;
		}
		else
		{
			return calcute(a-1,b)+calcute(a,b-1);
		}
	}
}

算法训练 5-2求指数

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i = 1; i <= b; i++) {
			int c = (int)Math.pow(a, i);
					System.out.printf("%12s",c);
					if (i%5==0) {
						System.out.println();
					}
		}
	}
}

算法提高 11-1实现strcmp函数

import java.util.Scanner;
 
public class Main {
	
public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
			if (a.length()>b.length()) {
				System.out.println(1);
				return;
			}
			if (b.length()>a.length()) {
				System.out.println(-1);
			}
			else{
			int c = a.compareTo(b);
     			if (c>0) {
				System.out.println(1);
			}
     			if (c<0){
				System.out.println(-1);
			}
     			else{
     			System.out.println(0);
     		}
		}
	}
}

9-1九宫格

import java.util.Scanner;
 
public class Main {
public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int f = sc.nextInt();
		int g = sc.nextInt();
		int h = sc.nextInt();
		int i = sc.nextInt();
		int z = a+b+c;
		int x = a+d+g;
		int v = a+e+i;
		int s = c+f+i;
		int q = d+e+f;
		int r = g+h+i;
		int t = c+e+g;
		int y = b+e+h;
		if (z==x&x==v&v==s&s==q&q==r&r==t&t==y) {
			System.out.println(1);
		}
		else{
			System.out.println(0);
		}
	}
}

算法提高 阶乘差`

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int p = sc.nextInt();
        long sum1 = 1,sum2 = 1;
        for(int i = 1;i<=n;i++) {
            sum1 = sum1*i;
        }
        for(int j = 1;j<= m;j++) {
            sum2 = sum2*j;
        }
        long s = (sum1-sum2)%p;
        System.out.println(s);
    }

}

算法提高 字符串跳步

import java.util.Scanner;
 
public class Main {
public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String d = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		char[]c = d.toCharArray();
		System.out.print(c[a]);
		int ci = 0;
		for (int i = 0; i < c.length; i++) {
			if (i>a) {
				ci++;
			}
			if (ci==b) {
				System.out.print(c[i]);
				ci=0;
			}
		}
	}
}

算法提高 11-2删除重复元素

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char[]b = a.toCharArray();
		int ci=0;
		for (int i = 0; i < b.length; i++) {
			for (int j = i+1; j < b.length; j++) {
				if(i+1<b.length){
					if(b[i]!=b[j]){
						continue;
					}
					else{
						b[j]='-';
						ci++;
					}
				}
			}
			if(ci>=1){
				b[i]='-';
			}
			ci=0;
		}
		for (int i = 0; i < b.length; i++) {
			if(b[i]=='-'){
				continue;
			}
			System.out.print(b[i]);
		}
	}
}

算法提高 9-3摩尔斯电码

import java.util.Scanner;

	    public class Main {  
	        public char Getchar(String A){ 
	            char result = 0;  

	             if(A.equals("*-"))  
	                 result = 'a';  
	         else if(A.equals("-***"))  
	             result = 'b';  
	         else if(A.equals("-*-*"))  
	             result = 'c';  
	         else if(A.equals("-**"))  
	             result = 'd';  
	         else if(A.equals("*"))  
	             result = 'e';  
	         else if(A.equals("**-*"))  
	             result = 'f';  
	         else if(A.equals("--*"))  
	             result = 'g';  
	         else if(A.equals("****"))  
	             result = 'h';  
	         else if(A.equals("**"))  
	             result = 'i';  
	         else if(A.equals("*---"))  
	             result = 'j';  
	         else if(A.equals("-*-"))  
	             result = 'k';  
	         else if(A.equals("*-**"))  
	             result = 'l';  
	         else if(A.equals("--"))  
	             result = 'm';  
	         else if(A.equals("-*"))  
	             result = 'n';  
	         else if(A.equals("---"))  
	             result = 'o';  
	         else if(A.equals("*--*"))  
	             result = 'p';  
	         else if(A.equals("--*-"))  
	             result = 'q';  
	         else if(A.equals("*-*"))  
	             result = 'r';  
	         else if(A.equals("***"))  
	             result = 's';  
	         else if(A.equals("-"))  
	             result = 't';  
	         else if(A.equals("**-"))  
	             result = 'u';  
	         else if(A.equals("***-"))  
	             result = 'v';  
	         else if(A.equals("*--"))  
	             result = 'w';  
	         else if(A.equals("-**-"))  
	             result = 'x';  
	         else if(A.equals("-*--"))  
	             result = 'y';  
	         else if(A.equals("--**"))  
	             result = 'z';  
	            return result;  
	        }  

	        public void Getsentence(String ch){  
	            String str1;  
	            StringBuilder[] str = new StringBuilder[1000];  
	            int j=0,count = 0;  
	            str[j] = new StringBuilder();         
	            for(int i=0;i<ch.length();i++){  
	                if(ch.charAt(i)=='|'){  
	                    j++;  
	                    str[j] = new StringBuilder();   
	                    count=j;  

	                }  
	                else{  

	                    String str2 = String.valueOf(ch.charAt(i));    
	                    str[j].append(str2);  
	                }  

	            }  
	            for(int k=0;k<=count;k++){  
	                str1 = str[k].toString();   
	                char temp = Getchar(str1);  
	                System.out.print(temp);  
	            }  


	        }  

	        public static void main(String[] args) {  
	            Main test = new Main();  
	            Scanner sc = new Scanner(System.in);  
	            String ch = sc.nextLine();  
	            test.Getsentence(ch);  

	        }  

	    }

算法训练 出现次数最多的整数

import java.util.Scanner;


public class Main {  
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();	
		if (n<=0) {		
		}
		else{
		int[] a = new int [n];
		int count = 0;
		int mcount = 0;
		int [] b = new int [1];	
		for (int i = 0; i < n; i++) {
			count=0;
			a[i]=sc.nextInt();
			for (int j = n-1; j >= 0; j--) {
				if (a[i]==a[j]) {
					count++;
					if (count > mcount) {
						mcount = count;
						b[0] = a[i];
					}
				}
			}
		}
		System.out.println(b[0]);
		}
	}   
}

算法提高 7-1用宏求球的体积

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double pi=3.1415926;
		double c = a*a*a*pi*4/3;
		System.out.format("%.5f", c);
	}
}

算法训练 前缀表达式`

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	char a =  sc.next().charAt(0);
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	if (a=='-') {
			System.out.println(b-c);
		}
    	if (a=='+') {
    		System.out.println(b+c);
    	}
    	if (a=='*') {
    		System.out.println(b*c);
    	}
    	if (a=='/') {
    		System.out.println(b/c);
    	}
    }
}

算法提高 7-2求arccos值

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	double a = sc.nextDouble();
    	System.out.printf("%.5f",Math.acos(a));
    }
}

算法训练 字串统计


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
 
public class Main {
	public static  void main(String[] args) {
	Scanner in=new Scanner(System.in);
	int l=0;
	String s="";
	 if(in.hasNext()){ 
         l = in.nextInt() ;
         s = in.next() ;
     }
	
	Map<String,Integer> map=new HashMap<String,Integer>(); 
	int maxValue=0;
	String maxStr="";
	 for(int i = 0 ; i < s.length() - l + 1 ; i ++){
         for(int j = i + l ; j < s.length() ; j ++){
             String str = s.substring(i,j) ;
			if(map.containsKey(str)){   
                int value = map.get(str) ;
                value ++ ;
                if(value > maxValue){
                    maxValue = value ;
                    maxStr = str ;
                }else if(value == maxValue){ 
                    if(maxStr.length() < str.length()){
                        maxStr = str ;
                    }
                }
                map.put(str, value) ;
            }else{ 
                map.put(str, 0) ;   
            }
        }
    }
    System.out.println(maxStr);
}
	
}

算法训练 大小写转换

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String a = sc.next(); 
    	   char[] c = a.toCharArray();
    	   for (int i=0;i<c.length;i++){
    	   c[i] = (char)((c[i]+(c[i]/97)*59+32)%123);          
    	   }          
    	   System.out.println(new String(c));      
    }
}

算法训练 删除数组零元素

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
    	   int[] c = new int[a];
    	   int[] b = new int[a];
    	   int count = 0;
    	   for (int i=0;i<a;i++){
    	   c[i] = sc.nextInt();
    	   if (c[i]!=0) {
			count++;
			b[count]=c[i];
    	   }
    	   }
    	   System.out.println(count);
    	   for (int j = 1; j <= count; j++) {
			System.out.print(b[j]+" ");
    	   }
    	         
    }
}

算法训练 P1102

import java.util.Arrays;
import java.util.Scanner;

class Student{
    String name;
    String gender;
    int age;
    int credit;
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        Student[] arr = new Student[num];
        for(int i = 0 ;i < arr.length;i ++) {
            arr[i] = new Student();
            arr[i].name = sc.next();
            arr[i].gender = sc.next();
            arr[i].age = sc.nextInt();
            arr[i].credit = sc.nextInt();
        }
        int j ;
        Student target = new Student();
        for(int i = 0 ;i < arr.length;i ++) {
            j = i;
            target = arr[i];
            while (j > 0 && target.credit < arr[j - 1].credit){
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = target;
        }
        for(int i = 0;i < arr.length;i ++) {
            System.out.println(arr[i].name + " " + arr[i].gender + " " + arr[i].age + " " + arr[i].credit);
        }
    }
}

算法训练 特殊的数字四十

public class Main {
    public static void main(String[] args) {
       for (int i = 1000; i < 10000; i++) {
		if (i%10+i/10%10+i/100%10+i/1000%10==10) {
			System.out.println(i);
		}
       }
    }
}

算法训练 s01串

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       if (a==0) {
		System.out.println("0");
       }
       if (a==1) {
    	   System.out.println("1");
       }
       if (a==2) {
    	   System.out.println("01");
       }
       if (a==3) {
    	   System.out.println("101");
       }
       if (a==4) {
    	   System.out.println("01101");
       }
       if (a==5) {
    	   System.out.println("10101101");
       }
       if (a==6) {
    	   System.out.println("0110110101101");
       }
       if (a==7) {
    	   System.out.println("101011010110110101101");
       }
       if (a==8) {
    	   System.out.println("0110110101101101011010110110101101");
       }
       if (a==9) {
    	   System.out.println("1010110101101101011010110110101101101011010110110101101");
       }
       if (a==10) {
    	   System.out.println("01101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==11) {
    	   System.out.println("101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==12) {
    	   System.out.println("01101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==13) {
    	   System.out.println("10101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==14) {
    	   System.out.println("0110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==15) {
    	   System.out.println("101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==16) {
    	   System.out.println("0110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==17) {
    	   System.out.print("1010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011");
    	   System.out.println("010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==18) {
    	   System.out.print("01101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110");
    	   System.out.print("10110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011");
    	   System.out.println("0101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
       if (a==19) {
    	   System.out.print("1010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011");
    	   System.out.print("0101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110");
    	   System.out.print("1011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101");
    	   System.out.print("0110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011");
    	   System.out.print("0101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110");
    	   System.out.print("1011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101");
    	   System.out.println("011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110110101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101");
       }
   }
}

算法训练 P1101

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       double sum = 0;
       String [] b = new String[a];
       double [] c = new double[a];
       double [] d = new double[a];
       for (int i = 0; i < a; i++) {
		b[i] = sc.next();
		c[i] = sc.nextDouble();
		d[i] = sc.nextDouble();
		sum+=c[i]*d[i];
	}
       System.out.format("%.6f", sum);
   }
}

算法提高 P1001

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       long a = sc.nextLong();
       long b = sc.nextLong();
       System.out.println(a*b);
   }
}

算法训练 P1101

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       double sum = 0;
       String [] b = new String[a];
       double [] c = new double[a];
       double [] d = new double[a];
       for (int i = 0; i < a; i++) {
		b[i] = sc.next();
		c[i] = sc.nextDouble();
		d[i] = sc.nextDouble();
		sum+=c[i]*d[i];
	}
       System.out.format("%.6f", sum);
   }
}

算法训练 最小乘积(基本型)

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
	
	public static void main(String[] args) {
		ArrayList alist1 = new ArrayList(); 	
		ArrayList alist2 = new ArrayList();		
		int b = 0; 
		Scanner sc = new Scanner(System.in);
		
		int t = sc.nextInt(); //t组数据
	
		
		int[] result = new int[1001];  //因为t小于等于1000
		
		for(int i=1 ; i<=t ; i++){  //分组输入  
			int n = sc.nextInt(); 		//定义每组一行有多少个元素
			for(int x=1 ; x<=2 ; x++){	//分两行输入
				
				for(int y=0 ; y<n ; y++){		//n个元素顺序输入
					alist1.add(sc.nextInt());  //直接将两行的数据输入到alist1中
				}
				
			}
			
			for(int x=n ; x<2*n ; x++){			
				alist2.add(alist1.get(x));   //将alist1中的第n个到最后一个数据元素顺序添加到alist2中,即第二行的数据
				
			}
			
			
			for(int x=n ; x<=2*n-1 ; x++){
			
				alist1.remove(n);			//将alist1中第n个到最后一个数据元素都删除,即剩余第一行的数据
			}
			Collections.sort(alist1);		//将alist1排序
			Collections.sort(alist2);		//将alist2排序
			Collections.reverse(alist2);	//将alist2呈倒序
			
			
			for(int y=0 ; y<n ; y++){
				b += (int)(alist1.get(y))*(int)(alist2.get(y));//两个数组的相同下标的数据元素相乘
			}
			result[i]=b;	//将乘积的和赋值给result数组 因为不一定只有一组数据
			//清楚数据后进行第下一组数据的计算
			alist1.clear();
			alist2.clear();
			b=0;
		}
		//输出每组数据的结果
		for(int i=1 ; i<=t ; i++){
			System.out.println(result[i]);
		}
	}
}

算法提高 拿糖果

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b;
       int sum = 0;
//       a!=3&a!=2&a!=5&a!=7
       while (a>=4) {
    	   b = (int) Math.sqrt(a);
    	   sum+=b;
    	   a-=2*b;
       }
       System.out.println(sum);
   }
}

算法提高 矩阵相乘

import java.util.Scanner;


public class Main {
  public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	   long a=sc.nextInt();
	   long aa=sc.nextInt();
	   long[][]aaa=new long[(int) a][(int) aa];
	   for (int i = 0; i <a; i++) {
		for (int j = 0; j <aa; j++) {
			aaa[i][j]=sc.nextInt();
		}
	}
	   
	   long b=sc.nextInt();
	   long bb=sc.nextInt();
	   long[][]bbb=new long[(int) b][(int) bb];
	   for (int i = 0; i <b; i++) {
			for (int j = 0; j <bb; j++) {
				bbb[i][j]=sc.nextInt();
			}
		}sc.close();
	   long[][]c=new long[(int) a][(int) bb];
	   for (int i = 0; i <a; i++) {
		for (int j = 0; j <bb; j++) {
			for (int k = 0; k <aa; k++) {
				c[i][j]+=aaa[i][k]*bbb[k][j];
			}
		}
	}
	   for (int i = 0; i <a; i++) {
		for (int j = 0; j <bb; j++) {
			System.out.print(c[i][j]+" ");
		}System.out.println();
	}
}
}

算法提高 c++_ch02_04

public class Main {
	    public static void main(String[] args) {    
	        for (int x = 2; x<=100;x++){
	           for (int y=2;y <= x;y++){
	               if (x%y==0 && x!=y){
	                   break;     
	               }
	               if(x%y == 0 && x==y){
	                   System.out.println(x);
	           }
	        }
	    }
	}
}

算法提高 3-2求存款

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        float balance = in.nextFloat();
        float ratio = in.nextFloat();
        in.close();
        System.out.printf("%.2f", (float)(balance + balance * 0.95 * ratio / 100.0));
    }
}

算法提高 3-3求圆面积表面积体积

import java.util.Scanner;


public class Main {
	public static final double PI = 3.1415926536;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		System.out.printf( "%20.10f%20.10f%20.10f",PI*r*r,4*PI*r*r,4*PI*r*r*r/3);
	}
}

算法训练 Torry的困惑(基本型)

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int count = 0;
		int sum = 1;
		for (int i = 2; i <= 1000000; i++) {
			for (int j = 2; j <= i; j++) {
				if (i%j==0 && i!=j) {
					break;
				}
				if (i%j==0 && i==j) {
					count++;
					if (count<a) {
						sum*=i;
					}
					if (count==a) {
						sum*=i;
						System.out.println(sum%50000);
						break;
					}
				}
			}
			if (a==count) {
				break;
			}
		}
	}
}

算法训练 寻找数组中最大值

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int k = 0;
		int max = 0;
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
			if (b[i]>max) {
				max = b[i];
				k = i;
			}
		}
		System.out.println(max+" "+k);
	}
}

算法训练 最大最小公倍数

import java.math.BigInteger;
import java.util.Scanner;
 
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		BigInteger num = new BigInteger("1");
		if(n<=2){
			System.out.println(2);
			return;
		}else{
			if(n%2 != 0){
				BigInteger t1 = new BigInteger(n+"");
				BigInteger t2 = new BigInteger((n-1)+"");
				BigInteger t3 = new BigInteger((n-2)+"");
				num=num.multiply(t1).multiply(t2).multiply(t3);
			}else{
				if(n%3 == 0){
					BigInteger t1 = new BigInteger((n-3)+"");
					BigInteger t2 = new BigInteger((n-1)+"");
					BigInteger t3 = new BigInteger((n-2)+"");
					num=num.multiply(t1).multiply(t2).multiply(t3);
					
				}else{
					BigInteger t1 = new BigInteger(n+"");
					BigInteger t2 = new BigInteger((n-1)+"");
					BigInteger t3 = new BigInteger((n-3)+"");
					
					num=num.multiply(t1).multiply(t2).multiply(t3);
					
				}
			}
		}
		System.out.println(num);
	}
}

算法提高 简单加法

public class Main {
	public static void main(String[] args) {
		int count = 0;
		for (int i = 1; i < 1000; i++) {
			if (i%3==0|i%5==0) {
				count+=i;
			}
		}
		System.out.println(count);
	}
}

算法训练 排序

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       if (a>b&a>c&b>c) {
		System.out.println(a+" "+b+" "+c);
       }
       if (a>b&a>c&c>b) {
    	   System.out.println(a+" "+c+" "+b);
       }
       if (b>a&b>c&a>c) {
    	   System.out.println(b+" "+a+" "+c);
       }
       if (b>a&b>c&c>a) {
    	   System.out.println(b+" "+c+" "+a);
       }
       if (c>a&c>b&b>a) {
    	   System.out.println(c+" "+b+" "+a);
       }
       if (c>a&c>b&a>b) {
    	   System.out.println(c+" "+a+" "+b);
       }
       if (a==b&b==c) {
    	   System.out.println(c+" "+a+" "+b);
       }
    }
}

算法提高 三个整数的排序

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       if (a>b&a>c&b>c) {
		System.out.println(a+" "+b+" "+c);
       }
       if (a>b&a>c&c>b) {
    	   System.out.println(a+" "+c+" "+b);
       }
       if (b>a&b>c&a>c) {
    	   System.out.println(b+" "+a+" "+c);
       }
       if (b>a&b>c&c>a) {
    	   System.out.println(b+" "+c+" "+a);
       }
       if (c>a&c>b&b>a) {
    	   System.out.println(c+" "+b+" "+a);
       }
       if (c>a&c>b&a>b) {
    	   System.out.println(c+" "+a+" "+b);
       }
       if (a==b&b==c) {
    	   System.out.println(c+" "+a+" "+b);
       }
    }
}
算法提高 身份证号码升级
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       long a = sc.nextLong();
       long b = a-(a%1000000000);
       long c = b * 100+19000000000l+(a%1000000000);
       String e = c+"";
       char [] d = new char [18];
       d=e.toCharArray();
       int sum = 0;
       int[] Wi = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};  
       for (int i = 0; i < d.length; i++) {
		 sum+=(d[i]-'0')*Wi[i];
       }
       sum %= 11;
       if (sum == 0) {
  		 System.out.println(e+"1");
         }
         if (sum == 1) {
      	   System.out.println(e+"0");
         }
         if (sum == 2) {
        	 System.out.println(e+"x");
         }
         if (sum == 3) {
        	 System.out.println(e+"9");
         }
         if (sum == 4) {
        	 System.out.println(e+"8");
         }
         if (sum == 5) {
        	 System.out.println(e+"7");
         }
         if (sum == 6) {
        	 System.out.println(e+"6");
         }
         if (sum == 7) {
        	 System.out.println(e+"5");
         }
         if (sum == 8) {
        	 System.out.println(e+"4");
         }
         if (sum == 9) {
        	 System.out.println(e+"3");
         }
         if (sum == 10) {
        	 System.out.println(e+"2");
         }
    }
}

算法训练 A+B problem

import java.util.Scanner;


public class Main {

	public static void main(String[] ages){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	System.out.println(a+b);
}
	}

算法训练 学做菜

import java.util.Scanner;

public class Main {

	public static void main(String[] ages) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int x = 0;
		int s = 0;
		int g = 0;
		int z = 0;
		int j = 0;
		for (int i = 0; i < 30; i++) {
			if (a - 2 >= 0 & b - 1 >= 0 & d - 2 >= 0) {
				x++;
				a -= 2;
				b -= 1;
				d -= 2;
				continue;
			}
			if (a - 1 >= 0 & b - 1 >= 0 & c - 1 >= 0 & d - 1 >= 0) {
				s++;
				a -= 1;
				b -= 1;
				c -= 1;
				d -= 1;
				continue;
			}
			if (c - 2 >= 0 & d - 1 >= 0) {
				g++;
				c -= 2;
				d -= 1;
				continue;
			}
			if (b - 3 >= 0) {
				z++;
				b -= 3;
				continue;
			}
			if (a - 1 >= 0 & d - 1 >= 0) {
				j++;
				a-=1;
				d-=1;
				continue;
			}
		}
		System.out.println(x);
		System.out.println(s);
		System.out.println(g);
		System.out.println(z);
		System.out.println(j);
	}
}

算法训练 寂寞的数

import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if (n<=2) {
			System.out.println(1);
			return;
		}
        TreeSet<Integer> ts=new TreeSet<Integer>();
        int m=1;
        int t=3;
        while(t<=n){
            int m2=m;
            int s=0;
            while(m2!=0){
                s+=m2%10;
                m2/=10;
            }
            m+=s;
            if(!ts.contains(m)&&m<=n){
                ts.add(m);
            }
            if(m>n){
                for(int i=t;;i++){
                    if(!ts.contains(i)){
                        m=i;
                        t=i+1;
                        break;
                    }
                }
            }
        }
        for(int i=1;i<=n;i++){
            if(!ts.contains(i)){
                System.out.println(i);
            }
        }
    }
}

算法训练 连续正整数的和

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 1;i<n;i++){
            int sum = 0;
            for (int j = i;j<n;j++){
                sum += j;
                if (sum == n){
                    System.out.print(i+" "+j);
                    System.out.println();
                    continue;
                }
                if (sum > n){
                    continue;
                }
            }
        }
    }
}

算法提高 快速幂

import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger a=sc.nextBigInteger();
		BigInteger b=sc.nextBigInteger();
		BigInteger p=sc.nextBigInteger();
		System.out.println(a.modPow(b, p));
	}
}

算法提高 题目1 最大最小值

import java.util.Scanner;

 class Main{
	 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] b = new int [a];
		int max = 0;
		int min = 1000000;
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
			if (b[i] > max) {
				max = b[i];
			}
			if (b[i] < min) {
				min = b[i];
			}
		}
		System.out.println(max+" "+min);
	}
 }

算法提高 扶老奶奶过街

public class Main {
	public static void main(String[] args) {
		System.out.println("A"+" "+"B"+" "+"E");
	}}

算法提高 新建Microsoft Word文档

import java.math.BigInteger;
import java.util.Arrays;
 
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;
 
	
public class Main {
	static Scanner in=new Scanner(System.in);
	public static  void main(String[] args) {
	int n=in.nextInt();
	int a[]=new int[2024];
	int k=1;
	while((n--)>0){
		String s;
		s=in.next();
		if(s.equals("New")){
			for(int i=1;i<=k;i++){
				if(a[i]==0){
					a[i]=1;
					System.out.println(i);
					k++;
					break;
				}
			}
			
		}
		else{
			int m=in.nextInt();
			if(a[m]==1){
				System.out.println("Successful");
				a[m]=0;
			}
			else{
				System.out.println("Failed");
			}
		}
		
	}
	
}
}	

算法提高 c++_ch02_01

public class Main {
    public static void main(String[] args) {

        System.out.println(65);
System.out.println(69);
System.out.println(73);
System.out.println(79);
System.out.println(85);
System.out.println(97);
System.out.println(101);
System.out.println(105);
System.out.println(111);
System.out.println(117);
    }
}

算法提高 逆序排列


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        Scanner in = new Scanner(System.in);
        while(true) {
            int a = in.nextInt();
            if(a == 0)
                break;
            list.add(a);
        }
        for(int i = list.size() - 1;i >= 0;i--)
            System.out.print(list.get(i)+" ");
    }
}

算法提高 十进制数转八进制数

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        ArrayList<Long> list = new ArrayList<Long>();
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        while(n > 0) {
            long temp = n % 2;
            n = n / 2;
            list.add(temp);
        }
        int len = list.size();
        if(len % 3 == 1) {
            list.add(0L);
            list.add(0L);
        } else if(len % 3 == 2) {
            list.add(0L);
        }
        len = list.size() / 3;
        long[] result = new long[len];
        int count = 0;
        for(int i = list.size() - 1;i >= 0;i = i - 3) {
            long a = list.get(i) * 2 * 2;
            long b = list.get(i - 1) * 2;
            long c = list.get(i - 2);
            result[count++] = a + b + c;
        }
        for(int i = 0;i < result.length;i++)
            System.out.print(result[i]);
    }
}

算法提高 第二大整数

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> al = new ArrayList<Integer>();
		for (int i = 0; i < 20; i++) {
			int n = sc.nextInt();
			if(n==0){
				break;
			}else{
				al.add(n);
			}
		}
		int arr[] = new int[al.size()];
		for (int i = 0; i < arr.length; i++) {
			arr[i]=al.get(i);
		}
		Arrays.sort(arr);
		System.out.println(arr[arr.length-2]);
	}

}

算法提高 约数个数

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int count = 0;
		for (int i = 1; i <= a; i++) {
			if (a%i==0) {
				count++;
			}
		}
		System.out.println(count);
	}
}

算法训练 友好数

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int sum = 0;
		int ci = 0;
		for (int i = 1; i < 10000; i++) {
			if (m%i==0) {
				sum+=i;
			}
			if (n%i==0) {
				ci+=i;
			}
		}
		if (ci==sum) {
			System.out.println("yes");
		}
		if (ci!=sum) {
			System.out.println("no");
		}
	}
}

算法训练 数的统计

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] b = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < a; j++) {
				if (i==b[j]) {
					count++;
				}
				if (j==a-1&count>0) {
					System.out.println(i+" "+count);	
					count=0;
				}
			}
		}
	}
}

算法训练 明明的随机数

import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []arr = new int[1001];
		int j;
		for(int i = 0; i < n; i++){
			j = sc.nextInt();
			arr[j]++;
		}
		int sum = 0;
		for(int i = 0; i < 1001; i++){
			if(arr[i] >= 1)
				sum++;
		}
		System.out.println(sum);
		for(int i = 0; i < 1001; i++){
			if(arr[i] >= 1)
				System.out.printf("%d ",i);
		}
	}
}

算法提高 6-17复数四则运算

import java.text.DecimalFormat;
import java.util.*;
public class Main{  
    public static void main(String[] args){  
        Scanner input=new Scanner(System.in);  
        double A1=input.nextDouble(),B1=input.nextDouble();
        char c=input.next().charAt(0);
        double A2=input.nextDouble(),B2=input.nextDouble(),A3=0,B3=0;
        if(c=='+'){
            A3=A1+A2;
            B3=B1+B2;
        }else if(c=='-'){
            A3=A1-A2;
            B3=B1-B2;
        }else if(c=='*'){
            A3=A1*A2-B1*B2;
            B3=A1*B2+B1*A2;
        }else if(c=='/'){
            if(A2==0&&B2==0){
                System.out.println("error");
                return;
            }
            A3=(A1*A2+B1*B2)/(A2*A2+B2*B2);
            B3=(B1*A2-A1*B2)/(A2*A2+B2*B2);
        }
        DecimalFormat format = new DecimalFormat("#0.#######");//DecimalForma类进行格式化输出
        System.out.print(format.format(A3)+(B3>0?"+":""));
        if(B3!=0)
        	System.out.print(format.format(B3)+"i");
    }  
}

算法训练 9-7链表数据求和操作

import java.util.Scanner;

public class Main {
	public static void fun(int arr[][])
	{    
		int s1=0;
		 
		for(int i=0;i<10;i++)
		{
			s1=s1+arr[i][0];
		} 
		int s2=0;
		 
		for(int j=0;j<10;j++)
		{
			s2=s2+arr[j][1];
		}
		
		System.out.print(s1+"+"+s2+"i");
	}
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
	  int arr[][]=new int [10][2];
	  for(int i=0;i<10;i++)
	  {
		    for(int j=0;j<2;j++)
		    {
		    	arr[i][j]=in.nextInt();
		    }
	  }
	  
	  
	  fun(arr);
				
	}
 
}

算法训练 6-3判定字符位置

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {   
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char [] b = a.toCharArray();
		int count = 0;
		for (int i = 0; i < b.length; i++) {
			count++;
			if (b[i]=='a'||b[i]=='e'||b[i]=='i'||b[i]=='o'||b[i]=='u') {
				System.out.println(count);
				break;
			}
			if (count==b.length) {
				System.out.println(0);
				break;
			}
		}
	}
}

算法提高 连接乘积

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
public class Main {
	public static void main(String[] args) {
		
		List<String> ansList = new ArrayList<String>();
		for (int i = 1; i < 99999; i++) {
			String fullPermutation = "";
			for (int n = 1; n < 10; n++) {
				fullPermutation = fullPermutation + String.valueOf( i*n );
				
				if( check(fullPermutation) ){
					ansList.add(fullPermutation);
				}
			}
		}
		
		Collections.sort(ansList);
		
		for(String s:ansList){
			System.out.println(s);
		}
	}
 
	private static boolean check(String fullPermutation) {
		int [] visit = new int[10];
		for (int i = 0; i < fullPermutation.length(); i++) {
			visit[ (byte)fullPermutation.charAt(i)-(byte)'0']++;
		}
		
		if(visit[0] > 0){
			return false;
		}
		
		for (int i = 1; i < visit.length; i++) {
			if(visit[i] != 1){
				return false;
			}
		}
		return true;
	}
}

算法训练 阿尔法乘积

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner  sc = new Scanner(System.in);
		String a = sc.next();
		char [] b = a.toCharArray();
		int sum = 1;
		for (int i = 0; i < b.length; i++) {
			if (b[i]!=48) {
				sum*=b[i]-'0';
				continue;
			}
		}
		if (sum>10) {
			a = sum+" ";
			b = a.toCharArray();
			sum=1;
			for (int i = 0; i < b.length-1; i++) {
				if (b[i]!=48) {
					sum*=b[i]-'0';
					continue;
				}
			}
		}
		if (sum>10) {
			a = sum+" ";
			b = a.toCharArray();
			sum=1;
			for (int i = 0; i < b.length-1; i++) {
				if (b[i]!=48) {
					sum*=b[i]-'0';
					continue;
				}
			}
		}
		if (sum>10) {
			a = sum+" ";
			b = a.toCharArray();
			sum=1;
			for (int i = 0; i < b.length-1; i++) {
				if (b[i]!=48) {
					sum*=b[i]-'0';
					continue;
				}
			}
		}
		if (sum>10) {
			a = sum+" ";
			b = a.toCharArray();
			sum=1;
			for (int i = 0; i < b.length-1; i++) {
				if (b[i]!=48) {
					sum*=b[i]-'0';
					continue;
				}
			}
		}
		if (sum>10) {
			a = sum+" ";
			b = a.toCharArray();
			sum=1;
			for (int i = 0; i < b.length-1; i++) {
				if (b[i]!=48) {
					sum*=b[i]-'0';
					continue;
				}
			}
		}
		System.out.println(sum);
	}
}

算法训练 薪水计算

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner ci=new Scanner(System.in);
		double n=ci.nextDouble(),m=ci.nextDouble();
		double z=0;
		if(n<=40) {
			z=n*m;
			System.out.printf("%.2f",z);
		}
		if(n<=50&&n>40) {
			z=40*m+(n-40)*m*1.5;
			System.out.printf("%.2f",z);
		}
		if(n>50) {
			z=55*m+(n-50)*m*2;
			System.out.printf("%.2f",z);
		}
	}
}

算法训练 整除问题

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		for (int i = a; i <= b; i++) {
			if (i%c==0) {
				System.out.print(i+" ");
			}
		}
	}
}

算法训练 数对

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		for (int i = 1; i <= a; i++) {
			for (int j = a; j > 0; j--) {
				if (i*j==a) {
					System.out.println(i+" * "+j+" = "+a);
				}
			}
		}
	}
}

算法训练 完数

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.close();
        int num = 1;
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                num += i;
            }
        }
        
        if (num == n && n != 1) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }
 
}

算法提高 复数归一化

import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		double c, d;
		c = a * 1.0 / Math.sqrt(a * a + b * b);
		d = b * 1.0 / Math.sqrt(a * a + b * b);
		System.out.printf("%.1f+%.1fi", c, d);
 
	}
}

算法提高 陶陶摘苹果

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int [] c = new int [a];
		int sum = 0;
		for (int i = 0; i < a; i++) {
			c[i] = sc.nextInt();
			if (c[i]<=b+30) {
				sum++;
			}
		}
		System.out.println(sum);
	}
}

算法提高 质因数2

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int sum = 0;
		int i = 2;
		while (a > 1) {
			if (a % i == 0) {
				a /= i;
				sum++;
				System.out.print(i + " ");
			} else
				i++;
		}
		System.out.println();
		System.out.println(sum);
	}
}

算法训练 黑色星期五

import java.time.DayOfWeek;
import java.util.Calendar;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int sum = 0;
		Calendar c = Calendar.getInstance();				//创建Calendar对象
		for (int i = 0; i < 12; i++) {
			c.set(a, i,13);									//0表示1月,11表示12月  
			if (c.get(Calendar.DAY_OF_WEEK) == 6)			//1表示周日...6表示周五,7表示周六
				sum++;
		}
		System.out.println(sum);
	}
}

算法训练 字符删除

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
        String s=sc.nextLine();
        String s2=sc.nextLine();char ch=s2.charAt(0);
        char[]ch2=s.toCharArray();
        for(int i=0;i<s.length();i++){
            if(ch2[i]==ch)
                continue;
            System.out.print(ch2[i]);
        }
        System.out.println();
        }
    }

}

算法训练 进制转换

import java.util.Scanner;
public class Main {
    public static void main(String args[]){
       Scanner input = new Scanner( System.in );
       String binaryString =input.nextLine();
       System.out.println(Integer.parseInt(binaryString,2));
    }
}

算法提高 输入输出格式练习

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String n=sc.next();
		System.out.println("987 | 654.8|b");
	}
}

算法提高 数字黑洞

import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		int s[] = new int[4];
		while (n != 6174) {
			int m = n;
			int i = 0;
			while (m != 0) {
				s[i] = m % 10;
				m /= 10;
				i++;
			}
			Arrays.sort(s);
			int s1 = s[0] * 1000 + s[1] * 100 + s[2] * 10 + s[3];
			int s2 = s[3] * 1000 + s[2] * 100 + s[1] * 10 + s[0];
			n = s2 - s1;
			sum++;
		}
		System.out.println(sum);
	}
}

算法训练 数的统计

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] b = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < a; j++) {
				if (i==b[j]) {
					count++;
				}
				if (j==a-1&count>0) {
					System.out.println(i+" "+count);	
					count=0;
				}
			}
		}
	}
}
算法训练 友好数
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int sum = 0;
		int ci = 0;
		for (int i = 1; i < 10000; i++) {
			if (m%i==0) {
				sum+=i;
			}
			if (n%i==0) {
				ci+=i;
			}
		}
		if (ci==sum) {
			System.out.println("yes");
		}
		if (ci!=sum) {
			System.out.println("no");
		}
	}
}

算法训练 反置数

import java.util.Scanner;
 
public class Main {
	public static int f(int n){
		String s=String.valueOf(n);
		char[]a1=s.toCharArray();
		String ss="";
		for (int i = a1.length-1; i >= 0; i--) {
			if (a1[i]==0) {
				continue;
			}
			ss+=a1[i];
		}
		int aa=Integer.parseInt(ss);
		return aa;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		int b =sc.nextInt();
		System.out.println(f(f(a)+f(b))+" ");
	}
}

算法训练 统计字符次数


import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char [] b = new char [a.length()];
		b=a.toCharArray();
		int count = 0;
		for (int i = 0; i < b.length; i++) {
			if ('0'<=b[i]&b[i]<='9') {
				count++;
			}
		}
		System.out.println(count);
	}
}

算法提高 计算器

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[] = new String[100];
		/** 将0-9数字存入数组a中,其中有红线的部分为1没有的部分为0 */
		a[0] = "1111110";
		a[1] = "0010010";
		a[2] = "0111101";
		a[3] = "0110111";
		a[4] = "1010011";
		a[5] = "1100111";
		a[6] = "1101111";
		a[7] = "0110010";
		a[8] = "1111111";
		a[9] = "1110111";
		int l = sc.nextInt();
		String b = sc.next();
		String c = sc.next();
		int bb[] = new int[l + 10];
		int cc[] = new int[l + 10];
		/** 将输入的字符串转化成数字 */
		for (int i = 0; i < l; i++) {
			bb[i] = b.charAt(i) - '0';
			cc[i] = c.charAt(i) - '0';
		}
		/** 求出需要变换的次数 */
		int sum = 0;
		for (int i = 0; i < l; i++)
			for (int k = 0; k < 7; k++)
				if (a[bb[i]].charAt(k) != a[cc[i]].charAt(k))// 比较两个数字所在的位置有几个不同的红线标记
					sum++;
		System.out.println(sum);
	}
}

算法提高 填充蛋糕


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = 3.1415926;
		double c = a*a*b+2*a*2*b;
		System.out.printf("%.1f",c);
	}
}

算法提高 寻找三位数

import java.util.Scanner;
 
public class Main {
 
    private static int[] num;
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        num = new int[9];
        in.close();
        dfs(0);
    }
 
    private static void dfs(int pos) {
        if (pos == 9) {
            int one = num[0] * 100 + num[1] * 10 + num[2];
            int two = num[3] * 100 + num[4] * 10 + num[5];
            int three = num[6] * 100 + num[7] * 10 + num[8];
            
            if (one * 2 == two && one * 3 == three) {
                System.out.println(one + " " + two + " " + three);
            }
            
            return;
        }
        
        for (int i = 1; i <= 9; i++) {
            if (isNotSelect(pos, i)) {
                num[pos] = i;
                dfs(pos + 1);
            }
        }
    }
    
    private static boolean isNotSelect(int pos, int value) {
        for (int i = 0; i < pos; i++) {
            if (num[i] == value) {
                return false;
            }
        }
        return true;
    }
 
}

算法训练 数组查找及替换

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int [] c = new int [a];
	char [] d = new char [a];
	for (int i = 0; i < a; i++) {
		c[i] = sc.nextInt();
	}
	Arrays.sort(c);
	for (int i = 0; i < a; i++) {
		if (c[i] % b !=0&c[i]<65||c[i]>90) {
			System.out.print(c[i]+" ");
		}
		if (c[i] % b !=0&c[i]>=65&c[i]<=90){
			d[i] = (char) (c[i]);
			System.out.print(d[i]+" ");
		}
	}
}
}

算法训练 判定数字


import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char b[] = a.toCharArray();
		if (b[0]>='0'&b[0]<='9') {
			System.out.println("yes");
		}
		else{
			System.out.println("no");
			return;
		}
	}
}

算法训练 统计字符次数


import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char [] b = new char [a.length()];
		b=a.toCharArray();
		int count = 0;
		for (int i = 0; i < b.length; i++) {
			if ('0'<=b[i]&b[i]<='9') {
				count++;
			}
		}
		System.out.println(count);
	}
}

算法训练 连接字符串

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = a+b;
		System.out.println(c);
	}
}

算法提高 三角形面积

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        in.close();
        double s = (a + b + c) / 2.0;
        System.out.printf("%.2f", Math.sqrt(s * (s - a) * (s - b) * (s - c)));
    }
 
}

算法提高 时间转换

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int h, m, s;
		h = t / 1440;
		m = (t - 1440 * h) / 60;
		s = t % 60;
		System.out.print(h + " " + m + " " + s);
	}
}

算法提高 计算整数因子

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		for (int i = 2; i <= a; i++) {
			for (int j = 2; j <= a; j++) {
				if (i%j==0&i!=j) {
					break;
				}
				if (i%j==0&i==j&a%i==0) {
					System.out.print(i+" ");
					break;
				}
			}
		}
	}
}

算法提高 GDP计算

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		double b = 0.1;
		double sum = 1;
		for (int i = 0; i < a; i++) {
			sum*=(1+b);
		}
		System.out.printf("%.2f",sum);
	}
}

算法提高 最长单词

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String [] s1 = s.split(" ");//通过空格把字符分开
		int max = 0, t = 0;
		for (int i = 0; i < s1.length; i++) {
			if (max < s1[i].length()) {
				max = s1[i].length();
				t = i;
			}
		}
		System.out.println(s1[t]);
	}
}

算法提高 字符串比较

import java.util.Scanner;

public class Main{
	 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int c = a.compareTo(b);
		if (c<0) {
			System.out.println(-1);
		}
		if (c==0) {
			System.out.println(0);
		}
		if (c>0) {
			System.out.println(1);
		}
	}
}

算法训练 P0501

import java.math.BigDecimal;
import java.util.Scanner;

public class Main{
	 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = sc.nextBigDecimal();
		BigDecimal b = sc.nextBigDecimal();
		BigDecimal c = new BigDecimal(1);
		c=a.multiply(b);
		System.out.println(c);
	}
}

算法训练 整数平均值

import java.util.Scanner;

public class Main{
	 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] b = new int [a];
		int sum = 0;
		for (int i = 0; i < b.length; i++) {
			b[i] = sc.nextInt();
			sum+=b[i];
		}
		System.out.println(sum/a);
	}
}

算法训练 4-3水仙花数

public class Main{
	 public static void main(String[] args) {

		for (int i = 100; i < 1000; i++) {
			if (((i%10)*(i%10)*(i%10))+((i/10%10)*(i/10%10)*(i/10%10))+((i/100%10)*(i/100%10)*(i/100%10))==i) {
				System.out.println(i);
			}
		}
	}
}

算法训练 幂方分解

import java.util.Scanner;
public class Main {

    public static void Mi(int num) {
        int flag = -1;
        if(num == 1) {
            System.out.print("2(0)");
            return;
        }
        if(num == 2) {
            System.out.print("2");
            return;
        }
        for(int i = 0;i < 15;i++) {
            if(num >= Math.pow(2, i) && num < Math.pow(2, i + 1)) {
                flag = i;
                break;
            }
        }
        if(flag == -1) {
            return;
        }else if(flag == 0) {
            System.out.print("2(0)");
        }else if(flag == 1) {
            System.out.print("2");
        }else {
            System.out.print("2(");
            Mi(flag);
            System.out.print(")");
        }

        if((int)(num - Math.pow(2 , flag)) == 0) {
            return;
        }else {
            System.out.print("+");
            Mi((int)(num - Math.pow(2 , flag)));
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        Mi(num);
    }
}

算法提高 2-1屏幕打印

public class Main{
	 public static void main(String[] args) {
		System.out.println("**********************");
		System.out.println("* My first C program *");
		System.out.println("**********************");
	}
}

算法提高 前10名

import java.util.Arrays;
import java.util.Scanner;

public class Main{
	 public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] b = new int[a];
		for (int i = 0; i < b.length; i++) {
			b[i] = sc.nextInt();
		}
		Arrays.sort(b);
		System.out.print(b[b.length-1]+" ");
		System.out.print(b[b.length-2]+" ");
		System.out.print(b[b.length-3]+" ");
		System.out.print(b[b.length-4]+" ");
		System.out.print(b[b.length-5]+" ");
		System.out.print(b[b.length-6]+" ");
		System.out.print(b[b.length-7]+" ");
		System.out.print(b[b.length-8]+" ");
		System.out.print(b[b.length-9]+" ");
		System.out.print(b[b.length-10]+" ");
	}
}

算法训练 大小写判断

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char c = in.next().charAt(0);
        in.close();
        if ('a' <= c && c <= 'z') {
            System.out.println("lower");
        } else if ('A' <= c && c <= 'Z') {
            System.out.println("upper");
        }
    }
 
}

算法提高 最长字符序列

import java.util.Scanner;
 
 
public class Main {
 
	static int count=0;
	public static void print(int line,int column,int temp[][]) {
		if(line!=0 && column!=0)
		{
			if(temp[line][column]==1)
			{
				count++;
				print(line-1, column-1, temp);
			}
			else if(temp[line][column]==2)
			{
				print(line, column-1, temp);
			}
			else
			{
				print(line-1, column, temp);
			}
		}
	}
	public static void fun(char arr1[],char arr2[],int line,int column,int arr[][],int temp[][]) {
		for(int i=0;i<=column;i++)
		{
			arr[0][i]=0;
		}
		for(int i=0;i<=line;i++)
		{
			arr[i][0]=0;
		}
		for(int i=1;i<=line;i++)
		{
			for(int j=1;j<=column;j++)
			{
				if(arr1[i-1]==arr2[j-1])
				{
					arr[i][j]=arr[i-1][j-1]+1;
					temp[i][j]=1;
				}
				else
				{
					if(arr[i-1][j]>=arr[i][j-1])
					{
						arr[i][j]=arr[i-1][j];
						temp[i][j]=3;
					}
					else
					{
						arr[i][j]=arr[i][j-1];
						temp[i][j]=2;
					}
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		while(scanner.hasNext())
		{
			String string1=scanner.next();
			String string2=scanner.next();
			char arr1[]=string1.toCharArray();
			char arr2[]=string2.toCharArray();
			int len1=arr1.length;
			int len2=arr2.length;
			int arr[][]=new int[len1+1][len2+1];
			int temp[][]=new int[len1+1][len2+1];
			count=0;
			fun(arr1,arr2,len1,len2,arr,temp);
			print(len1,len2,temp);
			System.out.println(count);
		}
	}
 
}

算法训练 二元函数

import java.util.Scanner;
import java.util.Stack;
 
public class Main {
	public static int a;
	public static int b;
 
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		a = s.nextInt();
		b = s.nextInt();
		String str = s.next();
 
		char chs[] = str.toCharArray();
		Stack<Integer> stack = new Stack<>();
		boolean flag = true;
		for (int i = 0; i < chs.length; i++) {
			if (chs[i] == '-') {
				flag = false;
			} else if (Character.isDigit(chs[i])) {
				int num = 0;
				for (; i < chs.length && Character.isDigit(chs[i]); i++) {
					num = num * 10 + Integer.parseInt(String.valueOf(chs[i]));
				}
				i--;
				if (flag) {
					stack.push(num);
				} else {
					stack.push(num * (-1));
					flag = true;
				}
			} else if (chs[i] == ')') {
				int y = stack.pop();
				int x = stack.pop();
				int r = f(x, y);
				stack.push(r);
			}
 
		}
		 f(2,f(1,f(1,-1)))
		System.out.println(stack.pop());
	}
 
	private static int f(int x, int y) {
		// TODO 自动生成的方法存根
		return a * x + b * y;
	}
}

算法训练 数位分离

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		if (a<=9) {
			System.out.println(a);
		}
		if (10<=a&a<=99) {
			System.out.println(a/10%10+" "+a%10);
		}
		if (100<=a&a<=999) {
			System.out.println(a/100%10+" "+a/10%10+" "+a%10);
		}
	}
}

算法训练 确定元音字母位置

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a = sc.next();
		char b [] = a.toCharArray();
		int count = 0;
		for (int i = 0; i < b.length; i++) {
			count++;
			if (b[i]=='a'||b[i]=='e'||b[i]=='i'||b[i]=='o'||b[i]=='u') {
				System.out.println(count);
				break;
			}
			if (count==b.length) {
				System.out.println(0);
			}
		}
	}
}

算法提高 3-1课后习题2

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int [] a = new int [10];
		int sum = 0;
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			sum+=a[i];
		}
		System.out.println(sum);
	}
}

算法提高 解二元一次方程组

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int e=sc.nextInt();
		int f=sc.nextInt();
		System.out.println((c*e-b*f)/(a*e-b*d)+" "+(c*d-a*f)/(b*d-a*e));
	}
}

算法训练 水仙花

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = a%10;
		int c = a/10%10;
		int d = a/100%10;
		if (b*b*b+c*c*c+d*d*d==a) {
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

算法训练 最长字符串

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String [] a = new String[5];
		for (int i = 0; i < 5; i++) {
			a[i] = sc.next();
		}
		String [] b = new String [1];
		b[0] = "a";
		for (int i = 0; i < a.length; i++) {
			if (a[i].length()>b[0].length()) {
				b[0] = a[i];
			}
		}
		System.out.println(b[0]);
	}
}

算法训练 最大值与最小值的计算

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int [] a = new int[11];
		for (int i = 0; i < 11; i++) {
			a[i] = sc.nextInt();
		}
		int max = 0;
		int min = 2100000000;
		for (int i = 0; i < a.length; i++) {
			if (a[i]>max) {
				max = a[i];
			}
			if (a[i]<min) {
				min = a[i];
			}
		}
		System.out.println(max+" "+min);
	}
}

基础练习 数列特征

import java.util.Arrays;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b [] = new int[a];
		int sum = 0;
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
			sum+=b[i];
		}
		Arrays.sort(b);
		System.out.println(b[a-1]);
		System.out.println(b[0]);
		System.out.println(sum);
	}
}

基础练习 字母图形

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				if (i==j) {
					int c = i-j+65;
					System.out.print((char)c);
				}
				if (i>j) {
					int c = i-j+65;
					System.out.print((char)c);
				}
				if (i<j) {
					int c = j-i+65;
					System.out.print((char)c);
				}
			}
			System.out.println();
		}
	}
}

基础练习 数列排序

import java.util.Arrays;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b [] = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
		}
		Arrays.sort(b);
		for (int i = 0; i < b.length; i++) {
			System.out.print(b[i]+" ");
		}
	}
}

相关标签: java