杭电OJ 2000~2007

🍑 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));//输出本年的第几天
        }
    }
}

🍑 HDOJ 2006 奇数乘积
在这里插入图片描述

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);
		}
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值