关于翁恺老师测试题1.2.3

1
温度转换(5分)

题目内容:

写一个将华氏温度转换成摄氏温度的程序,转换的公式是:

    °F = (9/5)*°C + 32

其中C表示摄氏温度,F表示华氏温度。

程序的输入是一个整数,表示华氏温度。输出对应的摄氏温度,也是一个整数。

提示,为了把计算结果的浮点数转换成整数,需要使用下面的表达式:

    (int)x;

其中x是要转换的那个浮点数。

 

注意:除了题目要求的输出,不能输出任何其他内容,比如输入时的提示,输出时的说明等等都不能。这道题目要求转换后的数字,程序就只能输出这个数字,除此之外任何内容都不能输出。

 

输入格式:

一个整数。

 

输出格式:

一个整数。

 

输入样例:

100

 

输出样例:

37

答案:

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        int F;
        
        double num = 9/5.0;
        
        Scanner in = new Scanner(System.in);
        F = in.nextInt();
        
        double  C = ((F - 32)/num); //公式换算后所得
        
        System.out.println((int)C);
    }

}

2

时间换算(5分)

题目内容:

UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8。现在,你的程序要读入一个整数,表示BJT的时和分。整数的个位和十位表示分,百位和千位表示小时。如果小时小于10,则没有千位部分;如果小时是0,则没有百位部分;如果分小于10分,需要保留十位上的0。如1124表示11点24分,而905表示9点5分,36表示0点36分,7表示0点7分。

有效的输入范围是0到2359,即你的程序不可能从测试服务器读到0到2359以外的输入数据。

你的程序要输出这个时间对应的UTC时间,输出的格式和输入的相同,即输出一个整数,表示UTC的时和分。整数的个位和十位表示分,百位和千位表示小时。如果小时小于10,则没有千位部分;如果小时是0,则没有百位部分;如果分小于10分,需要保留十位上的0。

提醒:要小心跨日的换算。

 

输入格式:

一个整数,表示BJT的时和分。整数的个位和十位表示分,百位和千位表示小时。如果小时小于10,则没有千位部分;如果小时是0,则没有百位部分;如果小时不是0而且分小于10分,需要保留十位上的0。

 

输出格式:

一个整数,表示UTC的时和分。整数的个位和十位表示分,百位和千位表示小时。如果小时小于10,则没有千位部分;如果小时是0,则没有百位部分;如果小时不是0而且分小于10分,需要保留十位上的0。

 

输入样例:

933

 

输出样例:

133

答案:

import java.util.Scanner;
public class Main {
    

    public static void main(String[] args) {
    
        Scanner in = new Scanner(System.in);
        
        final int T = 800;  //声明一个时差用于BJT-时差 8小时 即 800
        int input = 0;
        input = in.nextInt();
        int h = input/100;       //声明一个整型int h = 输入除以100 这样是为了在判断中判断百位与千位数字是在0-23之间 见if
        int m = input%100;       //声明一个整型int m = 输入取余100 这样是为了在判断中判断各位与十位数字是在0-59之间 见if
        
        
        if(h>=0&&h<=23&&m>=0&&m<=59&&input>=800) 
//如果 输入值除以100后的值>=0&&这个值<=23 && 输入值取余100后的值>=0且<=59 因为时间如果为60或更大则不是时间表达 && 输入值>=800 因为时差为800 8个小时 小于800会为负值
//在后面的else if中,输出的值为(输入值+2400-时差)即为有效时间

        {
            
            System.out.println(input-T);
            
            
        }
        else if(input<800&&input>=0)
        {
            System.out.println(input+2400-T);
            
        }

         
        
    }

    
}

3
信号报告(5分)

题目内容:

无线电台的RS制信号报告是由三两个部分组成的:

R(Readability) 信号可辨度即清晰度.

S(Strength)    信号强度即大小.

其中R位于报告第一位,共分5级,用1—5数字表示.

1---Unreadable

2---Barely readable, occasional words distinguishable

3---Readable with considerable difficulty

4---Readable with practically no difficulty

5---Perfectly readable

报告第二位是S,共分九个级别,用1—9中的一位数字表示

1---Faint signals, barely perceptible

2---Very weak signals

3---Weak signals

4---Fair signals

5---Fairly good signals

6---Good signals

7---Moderately strong signals

8---Strong signals

9---Extremely strong signals

现在,你的程序要读入一个信号报告的数字,然后输出对应的含义。如读到59,则输出:

Extremely strong signals, perfectly readable.

 

输入格式:

一个整数,信号报告。整数的十位部分表示可辨度,个位部分表示强度。输入的整数范围是[11,59]内有效的数字,这个范围外的数字不可能出现在测试数据中。

 

输出格式:

一句话,表示这个信号报告的意义。按照题目中的文字,先输出表示强度的文字,跟上逗号和空格,然后是表示可辨度的文字,跟上句号。注意可辨度的句子的第一个字母是小写的。注意这里的标点符号都是英文的。

 

输入样例:

33

 

输出样例:

Weak signals, readable with considerable difficulty.

答案:

import java.util.Scanner;

public class Main {

    private static String Stringr;  //声明静态私有字符串 Stringr
    private static String Strings;       //...        Strings

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int input = in.nextInt();
        int R = input/10;     //同第二题方法
        int S = input%10;    //同第二题方法
       // int valueRS = R*10+S;  已注释,之前的方法未达成遗留
        if(R>=1&&R<=5&&S>=1&&S<=9)//如果输入的数值在11-59之间 //if(R>=1&&R<=5&&S>=1&&S<=9&&input>=11&&input<=59) 之后检测input>=11&&input<=59是多余的
  { switch(S) //利用switch case 把S也就是各位数的值 赋值对应的String语句 { case 1: Strings = "Faint signals, barely perceptible"; break; case 2: Strings = "Very weak signals"; break; case 3: Strings = "Weak signals"; break; case 4: Strings = "Fair signals"; break; case 5: Strings = "Fairly good signals"; break; case 6: Strings = "Good signals"; break; case 7: Strings = "Moderately strong signals"; break; case 8: Strings = "Strong signals"; break; case 9: Strings = "Extremely strong signals"; } switch(R)  //同上,利用switch case 赋值十位数字的R 对应的String语句 { case 1: Stringr = "unreadable"; break; case 2: Stringr = "b;arely readable, occasional words distinguishable"; break; case 3: Stringr = "readable with considerable difficulty"; break; case 4: Stringr = "readable with practically no difficulty"; break; case 5: Stringr = "perfectly readable"; } System.out.println(Strings+", "+Stringr+"."); //输入完成后打印被赋值的 Strings 与 Stringr } } }

 

posted @ 2017-09-19 13:54  ukyo--君君小时候  阅读(304)  评论(0编辑  收藏  举报