Tsinsen 题解 1000-1024(已完结)

这是一系列关于算法题目的解题集合,涵盖了从1000到1024的题目,包括但不限于加法问题、01序列、长方形绘制、特殊数字计算、数列特征分析、杨辉三角形、陆地面积计算、整数查找、字串枚举、数列排序、集合运算、时间转换、瓷砖铺设等算法实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1000 A+B Problem 

import java.util.*;
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);
    }
}


1001 01序列

public class Main {
    public static void main(String args[]) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    for (int m = 0; m < 2; m++) {
                        for (int n = 0; n < 2; n++) {
                            for (int p = 0; p < 2; p++) {
                            System.out.print(i);
                            System.out.print(j);
                            System.out.print(k);
                            System.out.print(m);
                            System.out.print(n);
                            System.out.print(p);
                            System.out.println();
                            }
                        }
                    }
                }
            }
        }
    }
}


1002 01序列2

public class Main {
    public static void main(String args[]) {
        for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
                for (int c = 0; c < 2; c++) {
                    for (int d = 0; d < 2; d++) {
                        for (int e = 0; e < 2; e++) {
                            for (int f = 0; f < 2; f++) {
                                if ((a + b + c + d + e + f) % 2 == 1) {
                                    System.out.print(a);
                                    System.out.print(b);
                                    System.out.print(c);
                                    System.out.print(d);
                                    System.out.print(e);
                                    System.out.print(f);
                                    System.out.println();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


1003 画长方形1

public class Main {
    public static void main(String args[]){
        for(int i=1;i<=25;i++){
            for(int j=1;j<=18;j++){
                char result=(char)(Math.abs(i-j)+'A');
                System.out.print(result);
            }
            System.out.println();
        }   
    }
}


1004 画长方形2

import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char result=(char)(Math.abs(i-j)+'A');
                System.out.print(result);
            }
            System.out.println();
        }   
    }
}


1005 特殊的数字1

import java.util.*;
public class Main {
    public static void main(String args[]) {
        for(int n=100;n<=999;n++) {
            int x = n % 10;
            int y = n/10 % 10;
            int z = n/100;
            if(n==x*x*x + y*y*y + z*z*z)
                System.out.println(n);
        }
    }
}


1006 特殊的数字2

import java.util.*;
public class Main {
    public static void main(String args[]) {
        for(int n=1000;n<=9999;n++) {
            int a = n % 10;
            int b = n/10 % 10; 
            int c = n/100 % 10;
            int d = n/1000;
            if(n == d + 10*c + 100*b + 1000*a)
                System.out.println(n);
        }
    }
}


1007 特殊的数字3

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        sc.close();
        for (int n = 10000; n <= 999999; n++) {
            if (n >= 10000 && n <= 99999) { //五位数
                int a = n % 10;
                int b = n / 10 % 10;
                int c = n / 100 % 10;
                int d = n / 1000 % 10;
                int e = n / 10000;
                if (n == e + 10 * d + 100 * c + 1000 * b + 10000 * a && m == a + b + c + d + e) {
                    System.out.println(n);
                }
            } 
            else { //六位数
                int x = n % 10;
                int y = n / 10 % 10;
                int z = n / 100 % 10;
                int i = n / 1000 % 10;
                int j = n / 10000 % 10;
                int k = n / 100000;
                if (n == k + 10 * j + 100 * i + 1000 * z + 10000 * y + 100000 * x && m == x + y + z + i + j + k) {
                    System.out.println(n);
                }
            }
        }
    }
}


1008 数列特征

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


1009 数列特征2

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

1010 —— 1014 详见进制转换专题


1015 杨辉三角形

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


1016 缩小的陆地

import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double [][]a = new double[n][2];
        for(int i=0;i<n;i++) {
            for(int j=0;j<2;j++) {
             a[i][j] = sc.nextDouble();
            }
            double area = (a[i][0]*a[i][0] + a[i][1]*a[i][1]) * Math.PI / 2;
            if((int) (area/50) == area/50) {
                System.out.println(area/50);
            }
            else System.out.println((int) (area/50)+1);
        }
        sc.close();
    }
}


1017 计算价格

import java.util.*;
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();
        sc.close();
        System.out.println(3*a + 2*b + 8*c);
    }
}


1018 查找整数

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int x = sc.nextInt();
        sc.close();
        boolean flag = true; 
        for (int i = 0; i < n; i++)
            if (x == a[i]) {
                flag = false;
                System.out.println(i + 1);
                break;
            }
        if (flag)
            System.out.println(-1);
    }
}


1019 枚举字串

public class Main {
    public static void main(String[] args){
        for(int a=0;a<4;a++) {
            for(int b=0;b<4;b++) {
                for(int c=0;c<4;c++) {
                    for(int d=0;d<4;d++) {
                        System.out.print((char)(65+a));
                        System.out.print((char)(65+b));
                        System.out.print((char)(65+c));
                        System.out.print((char)(65+d)); 
                        System.out.println();
                    }
                }
            }
        }
    }
}


1020 数列排序

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(a);
        for (int i : a) {
            System.out.print(i+" ");
        }
    }
}


1021 集合运算 —见 详解


1022 时间转换

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        sc.close();
        // t = a*60*60 + b*60 + c
        int a = t/60/60; //时
        int b = (t-a*60*60) / 60;//分
        int c = t- a*60*60 - b*60;//秒
        System.out.println(a +":"+ b +":" +c);
    }
}


1023 瓷砖铺放

import java.util.*;
public class Main {
    public static int f(int n) {
        if(n==1) {
            return 1;
        }
        else if(n==2) {
            return 2;
        }
        else if(n>2) {
            return f(n-1) + f(n-2);
        }
        else return 0;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        System.out.println(f(n));
    }
}


1024 瓷砖问题再讨论 —见 详解


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值