蓝桥杯

49 阅读3分钟

image.png

package hello;
import java.util.*;
public class HH22 {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int min = 100, max = 0;
		double sum = 0;
		for(int i = 0; i < n; i++) {
			int x = scan.nextInt();
			min = Math.min(min, x);
			max = Math.max(max, x);
			sum+=x;
			
		}
		sum/=n;
		System.out.println(max);
		System.out.println(min);
		System.out.printf("%.2f", sum);
		
	}

}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		while(n>0) {
			System.out.print(n + " ");
			n/=2;
		}
		
	}

}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		char[] c = scan.next().toCharArray();
		StringBuilder str = new StringBuilder();
		for(int i=0;i<c.length;i++) {
			if(c[i]>='1'&&c[i]<='9') {
				int k=c[i]-'0';//字符数字转为int类型
				for(int j=0;j<k-1;j++) { //因为比如a3,只需要再加上2个a就行了
					str.append(c[i-1]);
				}
			}
			else {
				str.append(c[i]);
			}
		}
		System.out.println(str);
	}

}

image.png

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		float a = scan.nextFloat();
		System.out.printf("%.2f",a);
	}

}

image.png

package hello;
import java.util.*;
public class HH23 {

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

}

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		
		for(int i=0;i<t;i++) {
			int n = scan.nextInt();
			Set<Integer> set = new HashSet<>();
			for(int j=0;j<n;j++) {
				int x = scan.nextInt();
				if(set.contains(x)) {
					continue;
				}
				System.out.print(x + " ");
				set.add(x);
			}
			System.out.println();
		}
	}

}

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

  public static void main(String[] args) {
  	
  Map<Integer,Integer> map = new HashMap<>();
  Scanner scan = new Scanner(System.in);
  int n = scan.nextInt();
  int c = scan.nextInt();
  int[] arr = new int[n];
  for(int i=0;i<n;i++) {
  	arr[i] = scan.nextInt();
  	map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
  	
  }
  long res = 0;
  for(int i=0;i<n;i++) {
  	int b = arr[i] - c;
  	res+=map.getOrDefault(b, 0);
  	
  }
  System.out.println(res);
  	

}
}

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Stack<Integer> stack = new Stack<>();
		Scanner scan = new Scanner(System.in);
		while(scan.hasNextInt()) {
			int x = scan.nextInt();
			if(x==0) {
				break;
			}
			stack.push(x);
		}
		while(!stack.isEmpty()) {
			System.out.print(stack.pop()+" ");
		}
	}
}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Stack<Character> stack = new Stack<>();
		Scanner scan = new Scanner(System.in);
		char[] c = scan.next().toCharArray();
		int n = c.length;
		boolean fa = true;
		for(int i=0;i<n;i++) {
			if(c[i]=='@')break;
			if(c[i]=='(')stack.add(c[i]);
			if(c[i]==')') {
				if(stack.isEmpty()) {
					fa = false;
				}
				else stack.pop();
			}
		}
		if(!stack.isEmpty()) {
			fa = false;
			
		}
		if(fa) {
			System.out.print("YES");
		}
		else {
			System.out.print("NO");
		}
		
		
		
	}
}

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Queue<Integer>q = new LinkedList<>();
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		for(int i=1;i<=n;i++) {
			q.add(i);
		}
		int res = 0;
		while(!q.isEmpty()) {
			int x = q.poll();
			res++;
			if(res==m) {
				System.out.print(x+" ");
				res=0;
			}
			else q.add(x);
		}
	}
}

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int[] a =new int[3];
		for(int i=0;i<3;i++) {
			a[i]=scan.nextInt();
		}
		char []c = scan.next().toCharArray();
		Arrays.parallelSort(a);
		for(int i=0;i<3;i++) {
			System.out.print(a[c[i]-'A']+" ");
		}
	}
}

image.png

image.png

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int res = 0;
		for(char x:s.toCharArray()) {
			int k=x-'0';
			if(k>=0&&k<=9) {
				res++;
			}
		}
		System.out.println(res);
	}
}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int left=0,right=s.length()-1;
		boolean fa = true;
		while(left<right){
			if(s.charAt(left)!=s.charAt(right)) {
				fa = false;
			}
			left++;
			right--;
		}
		if(fa) {
			System.out.print("NO");
		}
		else {
			System.out.print("YES");
		}
	}
}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		char[] c = s.toCharArray();
		StringBuilder str = new  StringBuilder();
		StringBuilder a = new StringBuilder();
		for(int i=c.length-1;i>=0;i--) {
			if(c[i]==' ') {
				if(a.length()!=0) {
					int k=a.charAt(0)-'0';
					if(k>=0&&k<=9) {
						a.reverse();
					}
				}
				str.append(a +" ");
				a=new StringBuilder();
				
			}else {
				char x = c[i];
				if((x>'a'&&x<'z')||(x>='A'&&x<='Z')) {
					x^=32;
				}
				a.insert(0, x);
			}
		}
		if(a.length()!=0) {
			if(a.length()!=0) {
				int k=a.charAt(0)-'0';
				if(k>=0&&k<=9) {
					a.reverse();
				}
			}
			str.append(a);
			System.out.print(str);
		}
		  
		
	}
}

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int ans = 0;
		for(int i=1;i<n;i++) {
			long res = (long)i*i;
			res%=n;
			if(res*2<n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long ans = 0;
		for(int i=1;i<=n;i++) {
			String s = i+"";
			if(s.contains("2")||s.contains("0")||s.contains("1")||s.contains("9")) {
				ans+=i;
			}
		}
		System.out.println(ans);
	}
}

image.png

image.png

package hello;
import java.util.*;
public class HH23 {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a=new int[n];
		long sum =0,res=0;
		for(int i=0;i<n;i++) {
			a[i] = scan.nextInt();
			sum+=a[i];
		}
		for(int i=0;i<n;i++) {
			
			sum=sum-a[i];
			res+=sum*a[i];
		}
		System.out.println(res);
	}
}

image.png

image.png

image.png

image.png image.png