Tsinsen 题解 1053-1059(已完结)

Tsinsen 的题解系列涵盖1053到1059题目,包括"The Next Cow"的后续,奶牛罢工问题,字符串解析与芯片测试挑战,以及解决二元整数不定方程的策略。每个题目都附有详细解析,是编程解题爱好者的参考资料。

附:友情链接之 Tsinsen 第一卷 题解 1000-1024(已完结)          

                       Tsinsen 第一卷 题解 1025-1033(已完结)  

                         Tsinsen 第一卷 题解 1034-1043(已完结)

                        Tsinsen 第一卷 题解 1044-1052(已完结)


1053 The Next Cow

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        System.out.println(n+1); 
    }
}


1054 奶牛的罢工

import java.util.*;
public class Main {
    static boolean prime(int x) {
        if (x == 1)
            return false;
        for (int i = 2; i <= Math.sqrt(x); i++)
            if (x % i == 0) {
                return false;
            }
        return true;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        do {
            n = n + 2;
        } while (prime(n) == false);
        System.out.println(n);
    }
}


1055 “The Next Cow” Strikes Back

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = sc.next();
        String b = null;
        String c = null;
        int flag = 0;
        for (int i = 1; i <= n; i++) {
            b = sc.next();
            if (flag == 0) {
                if (a.compareTo(b) < 0) {
                    c = b;
                    flag = 1;
                }
            } else if (flag == 1) {
                if (b.compareTo(c) < 0 && b.compareTo(a) > 0) {
                    c = b;
                    System.out.println(c);
                }
            }
        }
        if (flag == 1) {
            System.out.println(c);
        } else if (flag == 0) {
            System.out.println("The End");
        }
    }
}


1056 Sine之舞 —见 详解


1057 FJ的字符串 —见 详解


1058 芯片测试 

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[20][20];
        int[] b = new int[20];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                a[i][j] = sc.nextInt();
                if (a[i][j] > 0) {
                    b[j]++;
                }
            }
        }
        sc.close();
        for (int i = 1; i <= n; i++) {
            if (b[i] >= (n + 1) / 2) {
                System.out.print(i);
                if (i != n) {
                    System.out.print(" ");
                }
            }
        }
    }
}

1059 求解二元整数不定方程

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String []s = str.split(",");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        int m = Integer.parseInt(s[2]);
        for (int x=1;x<m;x++){
               for (int y=1;a*x+b*y<=m;y++){
                  if(y>=x){
                      System.out.println(x+","+y);
                  }
               }
        }
    }
}

       

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值