安徽科技学院2017-2018-1学期15电信12《Java编程技术》期末考试

举报
楚楚冻人玥玥仙女 发表于 2021/11/19 02:02:48 2021/11/19
【摘要】 安徽科技学院2017-2018-1学期15电信12《Java编程技术》期末考试 缘分真是一个奇妙的东西,说来就来 可惜快乐的时光总是过得很快 JAVA程序设计课程就酱紫画上句号了,真的很不...

安徽科技学院2017-2018-1学期15电信12《Java编程技术》期末考试

缘分真是一个奇妙的东西,说来就来

可惜快乐的时光总是过得很快

JAVA程序设计课程就酱紫画上句号了,真的很不舍。。。

题面
排行榜

A:白色帽子

时间限制:1000 ms | 内存限制:65535 KB
描述
最近发现了一个搞笑的游戏,不过目前还没玩过。一个舞会上,每个人头上都戴着一顶帽子,帽子只有黑白两种,白的至少有一顶。每个人都能看到别人帽子的颜色,可是看不见自己的。主持人先让大家看看别人头上戴的是什么帽子,然后关灯,如果有人认为自己戴的是白色帽子,就打自己一个耳光( ,都很自觉,而且不许打别人的哦),开灯,关灯,开灯……。因为都不想打自己耳光,所以不确定的情况下都不会打自己的,现在有n顶白色帽子,第几次关灯才会听到有人打自己耳光?
输入
第一行只有一个整数m(m<=100000),表示测试数据组数。
接下来的m行,每行有一个整数n(n<=100000000),表示白色帽子的顶数。
输出
输出第几次关灯能听到耳光声,每组输出占一行。
样例输入
1
2
样例输出
2

import java.util.Scanner;


public class Main{
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = scanner.nextInt();
    while(T-->0){
        System.out.println(scanner.nextInt());
    }
}
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

B:苦恼的小明

时间限制:3000 ms | 内存限制:65535 KB
描述
小明又出问题了。妈妈认为聪明的小明应该更加用功学习而变的更加厉害,所以小明除了上学之外,还要参加妈妈为他报名的各科复习班。另外每周妈妈还会送他去学习朗诵、舞蹈和钢琴。但是小明如果一天上课超过八个小时就会不高兴,而且,上得越久就会越不高兴。假设小明不会因为其它事不高兴,并且她的不高兴不会持续到第二天。请你帮忙检查一下小明下周的日程安排,看看下周他会不会不高兴;如果会的话,哪天最不高兴。
输入
第一行输入N(0 < N < 100)表示测试数据组数,接下来每组测试数据输入包括七行数据,分别表示周一到周日的日程安排。每行包括两个小于10的非负整数,用空格隔开,分别表示津津在学校上课的时间和妈妈安排她上课的时间。
输出
每组测试数据输出包括一行,这一行只包含一个数字。如果不会不高兴则输出0,如果会则输出最不高兴的是周几(用1,2,3,4,5,6,7分别表示周一,周二,周三,周四,周五,周六,周日)。如果有两天或两天以上不高兴的程度相当,则输出时间最靠前的—天。
样例输入
1
5 3
6 2
7 2
5 3
5 4
0 4
0 6
样例输出
3
来源
经典水题

import java.util.Arrays;
import java.util.Scanner;

class Node {
    int x,y;
    Node (int x, int y){
        this.x = x;
        this.y = y;
    }


}
public class Main{
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = scanner.nextInt();
    while(T-->0){
        Node arr[]= new Node [7];
        int index = 0;
        int max = 0;
        for(int i = 0; i < 7; i ++){
            arr[i] = new Node(scanner.nextInt(),scanner.nextInt());
        }
        for(int i = 0; i < 7; i++){
            if(arr[i].x + arr[i].y > max){
                max = arr[i].x + arr[i].y;
                index = i+1;
            }
        }
        if(max < 8){
            System.out.println(0);
        }else{
            System.out.println(index);
        }
    }
}
}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

C:Dinner

时间限制:100 ms | 内存限制:65535 KB
描述
Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all to have one meal. As bowl, knife and other tableware is not enough in the kitchen, Little A goes to take backup tableware in warehouse. There are many boxes in warehouse, one box contains only one thing, and each box is marked by the name of things inside it. For example, if “basketball” is written on the box, which means the box contains only basketball. With these marks, Little A wants to find out the tableware easily. So, the problem for you is to help him, find out all the tableware from all boxes in the warehouse.
输入
There are many test cases. Each case contains one line, and one integer N at the first, N indicates that there are N boxes in the warehouse. Then N strings follow, each string is one name written on the box.
输出
For each test of the input, output all the name of tableware.
样例输入
3 basketball fork chopsticks
2 bowl letter
样例输出
fork chopsticks
bowl
提示
The tableware only contains: bowl, knife, fork and chopsticks.
来源
辽宁省10年省赛

import java.util.*;
public class Main{
    private static String str[] = {"bowl","knife","fork","chopsticks"};
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    while(scanner.hasNext()){
        int n = scanner.nextInt();
        String arr[] = new String[n];
        String save[] = new String[n];
        int j = 0;
        for(int i = 0; i < n; i++){
            arr[i] = scanner.next();
            if(contain(arr[i])){
                save[j++] = arr[i];
            }
        }
        if(save.length != 0){
            System.out.print(save[0]);
        }
        for(int i = 1; i < j;i++){
            System.out.print(" "+save[i]);
        }
        System.out.println();
    }
}

private static boolean contain(String string) {
    for(int i = 0; i < str.length; i++){
        if(string.equals(str[i])){
            return true;
        }
    }
    return false;
}
}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

D:词组缩写

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description

定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写。
比如,C语言里常用的EOF就是end of file的缩写。

Input

输入的第一行是一个整数T,表示一共有T组测试数据;
接下来有T行,每组测试数据占一行,每行有一个词组,每个词组由一个或多个单词组成;每组的单词个数不超过10个,每个单词有一个或多个大写或小写字母组成;
单词长度不超过10,由一个或多个空格分隔这些单词。

Output

请为每组测试数据输出规定的缩写,每组输出占一行。

Sample Input
1
end of file

Sample Output

EOF

import java.util.Scanner;


public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = Integer.parseInt(scanner.nextLine());
    while(T-->0){
        String str = scanner.nextLine();
        String arr[] = str.split("\\s+");

        String s = "";

        for(int i = 0; i < arr.length; i++){
            s += arr[i].substring(0,1).toUpperCase();
        }

        System.out.println(s);
    }
}
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

E:6174问题

时间限制:1000 ms | 内存限制:65535 KB

描述

假设你有一个各位数字互不相同的四位数,把所有的数字从大到小排序后得到a,从小到大后得到b,然后用a-b替换原来这个数,并且继续操作。例如,从1234出发,依次可以得到4321-1234=3087、8730-378=8352、8532-2358=6174,又回到了它自己!现在要你写一个程序来判断一个四位数经过多少次这样的操作能出现循环,并且求出操作的次数

比如输入1234执行顺序是1234->3087->8352->6174->6174,输出是4

输入

第一行输入n,代表有n组测试数据。
接下来n行每行都写一个各位数字互不相同的四位数

输出

经过多少次上面描述的操作才能出现循环

样例输入

1

1234

样例输出

4

import java.util.Arrays;
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = scanner.nextInt();
    while(T -- > 0){
        int n = scanner.nextInt();
        int count = 1;
        while(true){
            int temp = vary(n);
            if(temp == n){
                break;  
            }
            count++;
            n = temp;
        }
        System.out.println(count);

    }
}
    public static int vary(int n){
        int str[] = new int [4];
        str[0] = n%10;
        str[1] = n % 100 / 10;
        str[2] = n % 1000 / 100;
        str[3] = n / 1000;
        int a[] = str.clone();
        Arrays.sort(a);
        int b[] = new int [4];
         b[3] = a[0];
         b[2] = a[1];
         b[1] = a[2];
         b[0] = a[3];
         int va = 0,vb = 0;

         va = a[3] * 1000 + a[2] * 100 + a[1] * 10 + a[0];
         vb = b[3] * 1000 + b[2] * 100 + b[1] * 10 + b[0];

         return va - vb;
    }
}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

写这道题的时候,头很晕,所以代码写得特别恶心,现在自己都看不下去了,不过又懒得改了,童鞋们请见谅。。。

F:数列

莫蒂正在读小学,今天老师布置了几道数学题目。莫蒂平时上课经常不专心,这些他可发愁了,怎么办呢?看看你能不能帮帮他。

题目是给你一组有规律序列的前面5个整数,请你给出它后面跟着的5个整数,如:1,2,3,4,5,,,,,__。这是个等差数列,后面应该是6,7,8,9,10,就这么简单。而且现在莫蒂已经知道这串序列要么是等差数列,要么是等比数列。

Input

输入包含多组测试数据。每组输入5个整数,每个数字之间隔一个空格,当5个数字都为0时输入结束。

Output

对于每组输入,输出这串数列的后面5个数字,每个数字末尾包含一个空格。

Sample Input
1 2 3 4 5
1 2 4 8 16
0 0 0 0 0

Sample Output
6 7 8 9 10
32 64 128 256 512

Source
蚌埠学院第一届ACM程序设计大赛

import java.util.Scanner;


public class Main{
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNext()){
        int []a = new int[10];
        for(int i = 0; i < 5; i++){
            a[i] = scanner.nextInt();
        }
        if(a[0] == 0 && a[1] == 0 && a[2] == 0)break;
        if(a[0] + a[2] == 2* a[1]){
            for(int i = 5; i < 10; i++){
                a[i] = a[i-1] + (a[1] - a[0]);
            }
        }else{
            for(int i = 5; i < 10; i++){
                a[i] = a[i-1] * (a[1] / a[0]);
            }
        }

        for(int  i = 5; i < 10; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }
}
}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

G:素数三元组

时间限制:1000 ms | 内存限制:65535 KB

描述

相邻三个奇数都是素数是一种非常少见的情形,也就是三个奇数p-2, p, p+2都是素数,这样就形成了一个素数三元组。请找出三个数都不超过n的所有这样的素数三元组。

输入

输入多组数据,每组测试数据为一个正整数n,n <= 5000000。

输出

输出大小不超过n的所有的素数三元组,每行按照从小到大的顺序输出一个三元组中的三个数,两个数之间用空格间隔。如果不存在这样的素数三元组,请输出“No triple”。

样例输入

1

样例输出

No triple

import java.util.Scanner;


public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNext()){
        int n = scanner.nextInt();
        if(n <= 6){
            System.out.println("No triple");
        }else{

            System.out.println("3 5 7");
        }
    }
}

}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

这道题可以遍历查找,发现当n大于等于7的时候,只有3 5 7,所以我就直接把代码改成输出3 5 7了,简洁易懂。

H:不想挂科

最近快到期末考试了,HHN为了不挂科,在考前一周开始狂补。由于HHN太过随意,平时经常翘课,对考试内容一窍不通,这次恐怕凶多吉少。我们知道,最终成绩等于平时成绩的30%加上考试成绩的70%,如果达不到60分,就要挂科喽。HHN可以准确地估测出自己的平时成绩,现在他想知道如果不挂科,他的考试成绩必须达到多少分。
Input

第一行包含测试样例组数T。接下来是T组测试数据,每组数据仅包含一个整数m,代表HHN估测出的平时成绩。
Output

对每组数据,输出HHN不挂科所需的最低考试成绩。注意,考试成绩在0-100之间,且可以为小数点后一位为5的浮点数。
Sample Input

2
60
41
Sample Output

60
68.5
HINT

Source

蚌埠学院第一届ACM程序设计大赛

import java.util.Scanner;


public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = scanner.nextInt();
    while(T-->0){
        int m = scanner.nextInt();

        double b = (60 - 0.3 * m) / 0.7;

        double base = Math.floor(b);

        if(Math.abs(b - base) < 0.0001){
            System.out.println((int)b);
        }
        else if(b < base+0.5){
            System.out.println((int)b+".5");
        }else{
            System.out.println((int)b+1);
        }

    }
}
}
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

I:A+B’

Input
题目有多组输入
每行有一组数据为两个整数 A B(< =A,B < =1e6)
Output

A+B’的和
Sample Input

4 3
27 12
100 200
Sample Output

7
48
102
HINT

B’就是B反过来啦

Source

ICPC6th@ahstu

import java.util.Scanner;


public class Main{
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNext()){
        int a = scanner.nextInt(); 
        int b = scanner.nextInt();
        b = rev(b);
        System.out.println(a+b);
    }
}

private static int rev(int b) {
    // TODO Auto-generated method stub
    int ret = 0;
    while(b > 0){
        ret = ret * 10 + b%10;
        b/=10;
    }
    return ret;
}
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

J:最长字符串

时间限制:1.0s 内存限制:512.0MB

求出5个字符串中最长的字符串。每个字符串长度在100以内,且全为小写字母。

样例输入
one two three four five

样例输出
three

import java.util.Scanner;


public class Main{
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNext()){
        String s = scanner.nextLine();
        String arr[] = s.split("\\s+");
        String max = arr[0];
        for(int i= 1; i < arr.length; i++){
            if(arr[i].length()>max.length()){
                max = arr[i];
            }
        }
        System.out.println(max);
    }
}
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

文章来源: blog.csdn.net,作者:爱玲姐姐,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jal517486222/article/details/78888956

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。