刷题日记(一)

2000 ASCII码排序:

Problem Description 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

Input 输入数据有多组,每组占一行,有三个字符组成,之间无空格。

Output 对于每组输入数据,输出一行,字符中间用一个空格分开。

Sample Input

qwe
asd
zxc

Sample Output

e q w
a d s
c x z


ASCII(American Standard Code for Information Interchange:美国信息交换标准代码,是由7位(其余还有开头一位,为0),1和0组成的,来表示所有的大写和小写字母,数字0 到9、以及标点符号,并且在ASCII码中,数字的ASCII码<大写字母的ASCII码<小写字母的ASCII码。
使用Java的Arrays类的静态方法sort(),可以方便的进行排序,也可以通过Java的重写Comparator接口的compare()方法 ,来自定义排序规则。附上一些Arrays类的静态方法sort()可以实现的功能
这个比较简单,直接代码如下:


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

public class ASCIIsort {
	public static char[] ASCIISort(String str) {
		char[] arr = str.toCharArray();
		Arrays.sort(arr);
		return arr;
		

    }
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();		
		String[] str=new String[n];
		for(int i=0;i<n;i++) {
			str[i] = sc.next();
		}
		for(int j=0;j<n;j++) {
			System.out.println(ASCIISort(str[j]));
		}
	}
}

2001 计算两点间的距离

Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

Output 对于每组输入数据,输出一行,结果保留两位小数。

Sample Input

0 0 0 1
0 1 1 0

Sample Output

1.00
1.41



import java.util.Scanner;

public class LiangDianjuli {
	static double sum;
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	//一共几组
	int n=sc.nextInt();
	//一组一个DOUBLE
		
	//
	for(int i=0;i<n;i++) {
		double[] res=new double[4];
		System.out.println(String.format("%.2f", jisuan(res)));
	}
	}
	public static double jisuan(double[] str) {
			Scanner sc=new Scanner(System.in);
			str[0]=sc.nextDouble();	
			double n=str[0];
			str[1]=sc.nextDouble();
			double m=str[1];
			str[2]=sc.nextDouble();
			double x=str[2];
			str[3]=sc.nextDouble();
			double y=str[3];
			sum=Math.sqrt((n-x)*(n-x)+(m-y)*(m-y));	
		return sum;
}
}

2002 计算球体积

Problem Description 根据输入的半径值,计算球的体积。

Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。

Output 输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。

Sample Input

1
1.5

Sample Output

4.189
14.137



import java.util.Scanner;

public class qiuV {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		while(sc.hasNext()) {
			double PI=3.1415936;
			double a=sc.nextDouble();
			double b = 4*PI*a*a*a/3;
			System.out.println(String.format("%.2f", b));
		}
	
	}
}


2003 求绝对值

Problem Description 求实数的绝对值。

Input 输入数据有多组,每组占一行,每行包含一个实数。

Output 对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。

Sample Input

123
-234.00

Sample Output

123.00
234.00



import java.util.Scanner;

public class jueduizhi {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int num=0;
		while(num<n) {
			double a=sc.nextDouble();
			System.out.println(Math.abs(a));
			num++;
		}
	
	}
}


2004 成绩转换

Problem Description 输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:

90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;

Input 输入数据有多组,每组占一行,由一个整数组成。

Output 对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。

Sample Input

56
67
100
123

Sample Output

E
D
A
Score is error!



import java.util.Scanner;

public class zhaunhuan {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(input.hasNext()) {
			int n=input.nextInt();
			char s;
			if(n<0||n>100)
				System.out.println("Score is error!");
			else {
				if(n>=90)
					s='A';
				else if(n>=80)
					s='B';
				else if(n>=70)
					s='C';
				else if(n>=60)
					s='D';
				else
					s='E';
				System.out.println(s);
			}
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值