栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

PAT乙级(题号1001~1005)自解全AC Java实现

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PAT乙级(题号1001~1005)自解全AC Java实现

目录

1001、害死人不偿命的(3n+1)猜想(分数 15)

1002、写出这个数 (分数 20)

1003、我要通过!(分数 20)

1004、成绩排名(分数 20)

1005、继续(3n+1)猜想(分数 25)


1001、害死人不偿命的(3n+1)猜想(分数 15)

题目描述:

代码实现:

import java.util.*;

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

结果:

 


1002、写出这个数 (分数 20)

题目描述:

代码实现:

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String n = in.nextLine();
        HashMap NumDict = new HashMap<>();
        StringBuffer res = new StringBuffer();
        NumDict.put("0","ling");
        NumDict.put("1","yi");
        NumDict.put("2","er");
        NumDict.put("3","san");
        NumDict.put("4","si");
        NumDict.put("5","wu");
        NumDict.put("6","liu");
        NumDict.put("7","qi");
        NumDict.put("8","ba");
        NumDict.put("9","jiu");
        int sum = 0;
        for(int i = 0;i < n.length();i ++){
            sum += n.charAt(i) - '0';
        }
        String sum_ = String.valueOf(sum);
        for(int i = 0;i < sum_.length();i ++){
            res.append(NumDict.get(sum_.substring(i,i+1)) + " ");
        }
        System.out.println(res.substring(0,res.length() - 1));
    }
}

结果:


1003、我要通过!(分数 20)

题目描述:

代码实现:

先占个坑... ...

结果:


1004、成绩排名(分数 20)

题目描述:

代码实现:

import java.util.*;
import java.lang.*;
class Student implements Comparable{
    String name;
    String id;
    int score;
    Student(String name, String id,int score){
        this.name = name;
        this.id = id;
        this.score = score;
    }
    public int compareTo(Student other){
        if(this.score > other.score){
            return -1;
        }else if(this.score == other.score){
            return 0;
        }else{
            return 1;
        }
    }
    public String toString(){
        return this.name + " " + this.id;
    }
}



public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String space = in.nextLine();
        List stus = new ArrayList<>();
        while(n > 0){
            String input = in.nextLine();  
		    String[] info = input.split(" ");
            String name = info[0];
            String id = info[1];
            int score = Integer.parseInt(info[2]);
            stus.add(new Student(name, id, score));
            n--;
        }
        Collections.sort(stus);
        System.out.println(stus.get(0));
        System.out.println(stus.get(stus.size() - 1));
    }
}

结果:


1005、继续(3n+1)猜想(分数 25)

题目描述:

代码实现:

 先占个坑... ...

结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1031101.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号