🍑 OJ专栏
🍑 HDOJ 2000 ASCII码排序
👨🏫 注意输出尾空格
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
String s = sc.next();
char[] a = s.toCharArray();
Arrays.sort(a);
for (int i = 0; i < a.length; i++)
{
System.out.print(a[i]);
if (i != a.length - 1)
System.out.print(" ");
}
System.out.println();
}
}
}
🍑 HDOJ 2001 两点距离
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
System.out.printf("%.2f", Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
System.out.println();
}
}
}
🍑 HDOJ 2002 计算球体积
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double Pi = 3.1415927;//题目限定条件
while (sc.hasNext())
{
double r = sc.nextDouble();
double s = 4.0 / 3.0 * Pi * r * r * r;
System.out.printf("%.3f", s);
System.out.println();
}
}
}
🍑 HDOJ 2003 求绝对值
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
double x = sc.nextDouble();
System.out.printf("%.2f", Math.abs(x));
System.out.println();
}
}
}
🍑 HDOJ 2004 成绩转换
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int grade = sc.nextInt();
if (grade < 0 || grade > 100)
{
System.out.println("Score is error!");
} else
{
switch (grade / 10)
{
case 10:
System.out.println("A");
break;
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
}
}
}
}
🍑 HDOJ 2005 第几天?
🍺 API
💧 String.subString(开始下标,结束下标(**不包含**))
💧 date.lastIndexOf("/") :返回 "/" 在字符拆中最后出现的下标,没出现过则返回 -1
💧 GregorianCalendar calendar = new GregorianCalendar(年,月,日); //注意月份从0开始
💧 calendar.get(calendar.DAY_OF_YEAR));// 返回该日期在本年的第几天
import java.util.GregorianCalendar;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
String date = sc.next();
int idx = date.lastIndexOf("/");// 记录分隔符的下标
int y = Integer.valueOf(date.substring(0, 4));
int m = Integer.valueOf(date.substring(5, idx));
int d = Integer.parseInt(date.substring(idx + 1));// 直接从分隔符 取到最后
GregorianCalendar calendar = new GregorianCalendar(y, m - 1, d);// 注意月份从 0 开始
System.out.println(calendar.get(calendar.DAY_OF_YEAR));//输出本年的第几天
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int n = sc.nextInt();
int ans = 1;
while (n-- > 0)
{
int num = sc.nextInt();
if (num % 2 != 0)
ans = ans * num;
}
System.out.println(ans);
}
}
}
🍑 HDOJ 2007 平方和与立方和
👨🏫 m 不一定大于 n ,求的是 [n,m] 或 [m,n] 中的所有数
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
long a = sc.nextLong();
long b = sc.nextLong();
if (a > b)
{
a ^= b;
b ^= a;
a ^= b;
}
long ou = 0;
long ji = 0;
for (long i = a; i <= b; i++)
{
if (i % 2 == 0)
ou += i * i;
else
ji += i * i * i;
}
System.out.println(ou + " " + ji);
}
}
}