PAT练习题(1)

1001 害死人不偿命的(3n+1)猜想java

import java.util.Scanner;

public class Main{
    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int time = 0;
        while(n!=1){
            if(n%2 == 0){
                n = n/2;
                time++;
            }
            else{
                n = (3*n+1)/2;
                time++;
            }
        }
        System.out.println(time);
    }
}

1004 成绩排名

import java.util.Scanner;

public class Main{
    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
//将其存为一组数组,之后,每三个一查
//        ArrayList arrayList = new ArrayList();
//        arrayList
//没有数组,直接就是边输入,边比较

        String name1 = null;
        String name2 = null;
        String num1 = null;
        String num2 = null;
        int score = 0;
        int score3 = 101;
        for (int i = 0; i < n; i++) {
            String cin1 = sc.next();
            String cin2 = sc.next();
            int score2 = sc.nextInt();
            score3 = Math.min(score3,score2);
            if(score3 == score2){
                name1 = cin1;
                num1 = cin2;
            }
            score = Math.max(score,score2);
            if(score == score2){
                name2 = cin1;
                num2 = cin2;
            }
        }
        System.out.println(name2+" "+num2);
        System.out.println(name1+" "+num1);

    }
}

其实这道题,我有点想把数据寄存到一个一维数组里面,之后再按照隔位比较,最后发现还要涉及到强转,等等,感觉变麻烦了,最后,直接看了一下其他人的思路,边输入边比较就解决了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值