洛谷P1151、P1200、P1420、P1634题解(Java语言描述)
生活随笔
收集整理的這篇文章主要介紹了
洛谷P1151、P1200、P1420、P1634题解(Java语言描述)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
P1151題目要求
P1151題目鏈接
P1151題解
import java.util.Scanner;public class Main {public static void main(String[] args) {int count = 0;Scanner scan = new Scanner(System.in);int K = scan.nextInt();if (K > 0 && K < 3000) {for (int i = 10000; i<=30000; i++) {int a = i/10000;int b = (i - a*10000)/1000;int c = (i - a*10000 - b*1000)/100;int d = (i - a*10000 - b*1000 - c*100)/10;int e = (i - a*10000 - b*1000 - c*100 - d*10);int sub1 = a*100 + b*10 + c;int sub2 = b*100 + c*10 + d;int sub3 = c*100 + d*10 + e;if (sub1%K==0 && sub2%K==0 && sub3%K==0) {System.out.println(i);count++;}}if (count==0) {System.out.println("No");}}scan.close();} }P1200題目要求
P1200題目鏈接
P1200題解
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String star = scanner.nextLine();String ufo = scanner.nextLine();char[] starArr = star.toCharArray();char[] ufoArr = ufo.toCharArray();int starInt = 1;for (char c : starArr) {starInt *= (c-64);}int ufoInt = 1;for (char c : ufoArr) {ufoInt *= (c-64);}if (starInt % 47 == ufoInt % 47) {System.out.println("GO");} else {System.out.println("STAY");}scanner.close();}}P1420題目要求
P1420題目鏈接
P1420題解
import java.util.Scanner;public class Main {public static void main(String[] args) {int max = 1;int tmp = 1;Scanner scan = new Scanner(System.in);int n = scan.nextInt();if (n >= 1 && n <= 10000) {int[] number = new int[n+1];for (int i = 0; i < n; i++) {number[i] = scan.nextInt();}for (int i = 0; i < n; i++) {if (number[i+1] - number[i] == 1)tmp++;elsetmp = 1;if (tmp > max)max = tmp;}}System.out.println(max);scan.close();} }P1634題目要求
P1634題目鏈接
P1634題解
import java.util.Scanner; import java.util.ArrayList;public class Main {public static void main(String[] args) {ArrayList<Integer> collector= new ArrayList<>();int x = 0, y = 0, a = 0, b = 0, c = 0;int[] count = new int[10];Scanner scan = new Scanner(System.in);x = scan.nextInt();y = scan.nextInt();String stry = y + " ";int len2 = stry.length()-1;for (int i = x; i <= y; i++) {c = i;for (int j = len2-1; j >= 0; j--) {a = (int)Math.pow(10, j);b = c/a;c %= a;collector.add(b);}}for (int i : collector) {switch (i) {case 0:count[0] ++;break;case 1:count[1] ++;break;case 2:count[2] ++;break;case 3:count[3] ++;break;case 4:count[4] ++;break;case 5:count[5] ++;break;case 6:count[6] ++;break;case 7:count[7] ++;break;case 8:count[8] ++;break;case 9:count[9] ++;break;default:System.err.println("Error!");}}for (int i : count) {System.out.print(i + " ");}scan.close();}}都是以前寫的,如果lj,還請見諒
總結(jié)
以上是生活随笔為你收集整理的洛谷P1151、P1200、P1420、P1634题解(Java语言描述)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Fibonacci思想的灵活应用(洛谷P
- 下一篇: 【Java】蒙提霍尔问题的概率原理及随机