java洛谷刷题(入门2)

P5710 【深基3.例2】数的性质

import java.util.*;

public class Main {
    public static void main(String []args) {
 int z;
 Scanner x=new Scanner(System.in);
 z=x.nextInt();
        Boolean a=z%2==0;
        Boolean b=z>4&&z<=12;
if(a&&b){
    System.out.print(1+" ");
}else {
    System.out.print(0+" ");
}
        if(a||b){
            System.out.print(1+" ");
        }else {
            System.out.print(0+" ");
        }

        if((a&&!b)||(!a&&b)){
            System.out.print(1+" ");
        }else {
            System.out.print(0+" ");
        }
        if(!a&&(!b)){
            System.out.print(1+" ");
        }else {
            System.out.print(0+" ");
        }

}


}


P5711 【深基3.例3】闰年判断

import java.util.*;

public class Main {
    public static void main(String []args) {
 int a;
 Scanner x=new Scanner(System.in);
 a=x.nextInt();
 if(a%100==0){
     if(a%400==0){
         System.out.print(1);
     }else
     {
         System.out.print(0);
     }
 }else {
     if(a%4==0){
         System.out.print(1);
     }else
     {
         System.out.print(0);
     }
 }
    }

}


P5712 【深基3.例4】Apples

import java.util.*;

public class Main {
    public static void main(String []args) {
 int a;
 Scanner x=new Scanner(System.in);
 a=x.nextInt();
 if(a<=1){
 System.out.print("Today, I ate "+a+" apple.");
 }else
 {
     System.out.print("Today, I ate "+a+" apples.");
 }
    }


}


P5713 【深基3.例5】洛谷团队系统

import java.util.*;

public class Main {
    public static void main(String []args) {
 int a;
 Scanner x=new Scanner(System.in);
 a=x.nextInt();
 int b=5*a;
 int c=11+3*a;
 if(b<c){
     System.out.print("Local");
 }else {
     System.out.print("Luogu");
 }

    }


}


P5714 【深基3.例7】肥胖问题

import java.util.*;
import java.math.*;

public class Main {
    public static void main(String []args) {
double a,b,c;
Scanner x=new Scanner(System.in);
a=x.nextDouble();
b=x.nextDouble();
c=a/(b*b);
if(c<18.5){
    System.out.print("Underweight");
}else if(c>=18.5&&c<24){
    System.out.print("Normal");
}else if(c>=24){
    BigDecimal m = new BigDecimal(String.valueOf(c));
    BigDecimal n = BigDecimal.ONE;
    MathContext mc = new MathContext(6);
    System.out.println(m.divide(n, mc));
    System.out.print("Overweight");

}

    }


}


P5715 【深基3.例8】三位数排序

import java.util.*;


public class Main {
    public static void main(String []args) {

int []a=new int[3];
Scanner x=new Scanner(System.in);

for(int i=0;i<3;i++){
    a[i]=x.nextInt();
}
        int temp;
for(int i=0;i<3;i++){

    for(int j=0;j<i;j++){
        if(a[j]>a[i]){
            temp=a[j];
            a[j]=a[i];
            a[i]=temp;
        }
    }
}
for(int i=0;i<3;i++){
    System.out.print(a[i]+" ");
}
    }

}


P5716 【深基3.例9】月份天数

import java.util.*;

public class Main {
    public static void main(String []args) {
        int a,c,b;
        Scanner x=new Scanner(System.in);
        a=x.nextInt();
        c=x.nextInt();
        if(a%100==0){
            if(a%400==0){
                b=1;
            }else
            {
                b=0;
            }
        }else {
            if(a%4==0){
                b=1;
            }else
            {
               b=0;
            }
        }
        
        if(b==1){
            if(c==1||c==3||c==5||c==7||c==8||c==10||c==12){
                System.out.print("31");
            }else if(c==2){
                System.out.print("29");
            }else if (c==4||c==6||c==9||c==11){
                System.out.print("30");
            }
        }else if(b==0){
            if(c==1||c==3||c==5||c==7||c==8||c==10||c==12){
                System.out.print("31");
            }else if(c==2){
                System.out.print("28");
            }else if (c==4||c==6||c==9||c==11){
                System.out.print("30");
            }
        }
        
        
    }

}


P1085 [NOIP2004 普及组] 不高兴的津津

import java.util.*;

public class Main {
    public static void main(String[] args) {
            Scanner x = new Scanner(System.in);
            int[][] a = new int[2][7];
            for (int i = 0; i < 7; i++) {
                for (int j = 0; j < 2; j++) {
                    a[j][i] = x.nextInt();
                }
            }
            int[] b = new int[7];
            int[] c = new int[7];
            for (int i = 0; i < 7; i++) {
                b[i] = a[0][i] + a[1][i];
                c[i] = a[0][i] + a[1][i];

            }

            boolean flag = false;
        int day = 0;
            for (int i = 0; i < 7; i++) {
                if (b[i] > 8) {
                    flag = true;
                }
            }

            if (flag==true) {
                Arrays.sort(b);
                for (int i = 0; i < 7; i++) {
                    if (b[6] == c[i]) {
                        day = i + 1;
                        break;
                    }
                }
                System.out.println(day);
            } else {
                System.out.println(0);
            }
        }
    }

P1909 [NOIP2016 普及组] 买铅笔

import java.util.*;

public class Main {
    public static void main(String[] args) {
         int a;
         int b1,b2;
         int c1,c2;
         int d1,d2;
         Scanner x=new Scanner(System.in);
         a=x.nextInt();
        b1=x.nextInt();b2=x.nextInt();
        c1=x.nextInt();c2=x.nextInt();
        d1=x.nextInt();d2=x.nextInt();
        int m1,m2,m3;
        if(a%b1!=0){
         m1=(a/b1+1)*b2;}
        else {
             m1=(a/b1)*b2;
        }
        
        if(a%c1!=0){
         m2=(a/c1+1)*c2;}
        else  {
             m2=a/c1*c2;
        }
        
        if(a%d1!=0){
         m3=(a/d1+1)*d2;}
        else {
             m3=(a/d1*d2);
        }

        if(m1<=m2&&m1<=m3){
            System.out.print(m1);
        }else if(m2<=m1&&m2<=m3){
            System.out.print(m2);
        }else if (m3<=m1&&m3<=m2){
            System.out.print(m3);
        }
        }
    }


P1055 [NOIP2008 普及组] ISBN 号码

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner x=new Scanner(System.in);
        String a=x.next();
        String b=a.replace("-","");
        int sum=0;
        for(int i=0;i<b.length()-1;i++){
            sum+=(b.charAt(i)-'0')*(i+1);
        }
        if((sum%11==(b.charAt(b.length()-1)-'0'))||(sum%11==10&&(b.charAt(b.length()-1))=='X'))
            System.out.println("Right");
        else if(sum%11==10){
            System.out.println(a.substring(0,a.length()-1)+'X');
        }else{
            System.out.println(a.substring(0,a.length()-1)+sum%11);
        }

    }
}

P1422 小玉家的电费

import java.text.DecimalFormat;
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
      double n,m;
      Scanner x=new Scanner(System.in);
      n=x.nextDouble();
      if(n<=150){
          m=n*0.4463;
          DecimalFormat f = new DecimalFormat("#0.0");
          String d = f.format(m);
          System.out.print(d);
      }else if(n>=151&&n<=400){
          m=150*0.4463+(n-150)*0.4663;
          DecimalFormat f = new DecimalFormat("#0.0");
          String d = f.format(m);
          System.out.print(d);
      }else if(n>=401){
          m=150*0.4463+250*0.4663+(n-400)*0.5663;
          DecimalFormat f = new DecimalFormat("#0.0");
          String d = f.format(m);
          System.out.print(d);
      }
    }
}

P1888 三角函数

import java.util.Scanner;

public class Main {
	static public void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = sc.nextDouble();
		if (a > b) {
			double f = a;
			a = b;
			b = f;
		}
		if (a > c) {
			double f = a;
			a = c;
			c = f;
		}
		if (b > c) {
			double f = b;
			b = c;
			c = f;
		}
		double min = a;
		double max = c;
		for (double i = 2; i <= min; i++) {
			if (min % i == 0 && max % i == 0) {
				min /= i;
				max /= i;
				i = 1;
			}
		}
		System.out.printf("%.0f/%.0f",min,max);
		sc.close();
	}

}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mingshengda

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值