用Java语言做ACM的注意事项

①用Java时只需要粘贴包里面的内容,包名是不需要的。//有包名的去掉包名

②提交题目时类名一定要是 Main,否则判题系统是不认识代码的。

  ③Java的util类里面的Scanner.in里面的 input(自己定义的输入类名).hasNext();用于判断输入数据是否结束非常好用,比起C/C++的EOF/NULL好用

例题

import java.util.Scanner;
public class Main{
   public static void main(String[] args){
       Scanner input=new Scanner(System.in);
       while(true){
           int a=input.nextInt(), b=input.nextInt();
           if(a==0 && b==0)
               break;
           System.out.println(a+b);
       }
   }
}
View Code
import java.util.Scanner;
public class Main{
   public static void main(String[] args){
       Scanner input=new Scanner(System.in);
       int n=input.nextInt();
       while((n--)!=0){
           int sum=0,m=input.nextInt();
           for(int i=0;i<m;i++)
               sum+=input.nextInt();
           System.out.println(sum);
           if(n>0)
           System.out.println();
       }
   }
}
View Code

暂时就这么多了

附上一个简单数学题

ZOJ Problem Set - 3203 Light Bulb

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     
 5     public static void main(String[] args)
 6     {
 7     
 8     Scanner    scanner = new Scanner(System.in);
 9          //   int T;
10            // double H1,h1,D1;
11             int  T1 = scanner.nextInt();
12             while(T1!=0)
13             {
14                 T1--;
15                 double H1 = scanner.nextDouble();
16                 double h1 = scanner.nextDouble();
17                 double D1 = scanner.nextDouble();
18                 double temp=Math.sqrt((H1-h1)*D1);
19                 double temp2=(H1-h1)*D1/H1;
20                 if(temp>=D1)
21                     System.out.println(String.format("%.3f",h1));
22                     //printf("%.3lf\n",h1);
23                 else if(temp<temp2)
24                     System.out.println(String.format("%.3f",h1*D1/H1));
25                 //    printf("%.3lf\n",h1*D1/H1);
26                 else
27                 {
28                     double ans=D1+H1-temp-(H1-h1)*D1/temp;
29              
30                    System.out.println(String.format("%.3f", ans));
31                 }
32             }
33            
34         }
35 
36 
37     }
View Code

其他以后补充

转载于:https://www.cnblogs.com/DWVictor/p/10187112.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值