[個人記錄]小白書學習1.5習題(算法競賽入門經典第一版)


package one;

import java.util.Scanner;

public class one_z {
	/**
	 * 1.5習題
	 */
	public  static void main(String[] args) {
		//1-1平均數
		/*Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		double c=sc.nextDouble();
		System.out.printf("%.3f",(a+b+c)/3);	*/	
		//1-2溫度
		/*Scanner sc1=new Scanner(System.in);
		double f=sc1.nextDouble();
		System.out.printf("c=%.3f",5*(f-32)/9);*/
		//1-3連續和(目的是解決問題)
		/*Scanner sc2=new Scanner(System.in);
		int n;
		n=sc2.nextInt();
		System.out.printf("sum=%d",(1+n)*n/2);*/
		//1-4正弦和餘弦
		/*Scanner sc3=new Scanner(System.in);
		int n=sc3.nextInt();
		System.out.printf("sin=%f cos=%f",Math.sin(n*Math.PI/180),Math.cos(n*Math.PI/180));*/
		//1-5距離
		/*Scanner sc4=new Scanner(System.in);
		double x1=sc4.nextDouble();
		double y1=sc4.nextDouble();
		double x2=sc4.nextDouble();
		double y2=sc4.nextDouble();
		System.out.printf("distance=%f",Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2)));*/
		//1-6偶數
		/*Scanner sc5=new Scanner(System.in);
		int m=sc5.nextInt();
		if(m%2==0) {
			System.out.println("yes");
		}
		else {
			System.out.println("no");
		}*/
		//1-7打折
		/*Scanner sc6=new Scanner(System.in);
		int n=sc6.nextInt();
		double sum=n*95;
		if(sum>=300) {
			sum=sum*0.85;
		}
		System.out.printf("%.2f",sum);*/
		//1-8絕對值
		/*double s;
		Scanner sc7=new Scanner(System.in);
		s=sc7.nextDouble();
		System.out.printf("%.2f",Math.abs(s));*/
		//1-9三角形
		/*int a,b,c;
		Scanner sc8=new Scanner(System.in);
		a=sc8.nextInt();
		b=sc8.nextInt();
		c=sc8.nextInt();
		if(a+b>c&&a-b<c) {
			System.out.println("yes");
		}
		else {
			System.out.println("no a triangle");
		}*/
		//1-10年份
		Scanner sc9=new Scanner(System.in);
		int year=sc9.nextInt();
		if((year%4==0&&year%100!=0)||year%400==0) {
			System.out.println("yes");
		}
		else {
			System.out.println("no");
		}
	}
}

算法競賽入門學習

一邊看書一邊將原文中的C語言改爲Java語言編寫




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章