import java.util.*;
public class main{
public static void main(String[] args) {
int x1, y1, x2, y2;
double mid_x, mid_y;
Scanner sc = new Scanner(System.in);
x1 = sc.nextInt();
y1 = sc.nextInt();
x2 = sc.nextInt();
y2 = sc.nextInt();
mid_x = (x1 + x2)/2.0;
mid_y = (y1 + y2)/2.0;
if(Math.abs(mid_x) > Math.abs((int)mid_x))
{
if(Math.abs(mid_y) > Math.abs((int)mid_y))
{
//x小數 y小數
System.out.printf("(" + mid_x + "," + mid_y + ")");
}
else
{
//x小數 y整數
System.out.printf("(" + mid_x + "," + (int)mid_y + ")");
}
}
else
{
if(Math.abs(mid_y) > Math.abs((int)mid_y))
{
//x整數 y小數
System.out.printf("(" + (int)mid_x + "," + mid_y + ")");
}
else
{
//x整數 y整數
System.out.printf("(" + (int)mid_x + "," +(int) mid_y + ")");
}
}
}
};
2017年3月20日 星期一
[瘋狂程設]M90H011:整數商餘
import java.util.*;
public class main{
public static void main(String arge[]){
int m, n;
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
System.out.println();
System.out.println(m + " / " + n + "=" + (m/n));
System.out.print(m + " mod " + n + "=" + (m%n));
}
}
public class main{
public static void main(String arge[]){
int m, n;
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
System.out.println();
System.out.println(m + " / " + n + "=" + (m/n));
System.out.print(m + " mod " + n + "=" + (m%n));
}
}
2017年3月15日 星期三
[瘋狂程設]M90H007:考試調分(低成60高100)
import java.util.*;
import java.util.Arrays;
public class main{
public static void main(String arge[]){
int newGrade;
int[] a;
int min = 101;
int max = -1;
a = new int[60]; //存60個同學的成績
Scanner sc = new Scanner(System.in);
//輸入60個同學的成績
for(int i = 0;i<a.length;i++)
{
a[i] = sc.nextInt();
}
//找出最大最小值,為了求方程式
for(int i = 0;i<60;i++)
{
if(a[i] < min)
{
min = a[i];
}
if(a[i] > max)
{
max = a[i];
}
}
//newGrade = A * oldGrade + B
float A = 40 / (float)(max - min);
float B = (60 - (A * (float)min));
for(int i = 0;i<a.length;i++)
{
//以線性方式提高分數,四捨五入
a[i] = Math.round(A * a[i] + B);
//如果分數高於100,以100紀錄
if(a[i]>100)
{
a[i] =100;
}
}
//輸出同學們的分數
for(int i = 0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
import java.util.Arrays;
public class main{
public static void main(String arge[]){
int newGrade;
int[] a;
int min = 101;
int max = -1;
a = new int[60]; //存60個同學的成績
Scanner sc = new Scanner(System.in);
//輸入60個同學的成績
for(int i = 0;i<a.length;i++)
{
a[i] = sc.nextInt();
}
//找出最大最小值,為了求方程式
for(int i = 0;i<60;i++)
{
if(a[i] < min)
{
min = a[i];
}
if(a[i] > max)
{
max = a[i];
}
}
//newGrade = A * oldGrade + B
float A = 40 / (float)(max - min);
float B = (60 - (A * (float)min));
for(int i = 0;i<a.length;i++)
{
//以線性方式提高分數,四捨五入
a[i] = Math.round(A * a[i] + B);
//如果分數高於100,以100紀錄
if(a[i]>100)
{
a[i] =100;
}
}
//輸出同學們的分數
for(int i = 0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
[瘋狂程設]G001:長寬高算體積
import java.util.*;
public class main{
public static void main(String arge[]){
int x, y, z;
int m;
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
m = x*y*z;
System.out.print(m);
}
}
public class main{
public static void main(String arge[]){
int x, y, z;
int m;
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
m = x*y*z;
System.out.print(m);
}
}
[瘋狂程設]F020:計算BMI
import java.util.*;
import java.lang.*;
public class main{
public static void main(String arge[]){
double h, w;
Scanner sc = new Scanner(System.in);
h = sc.nextFloat();
w = sc.nextFloat();
double BMI;
BMI = w/(Math.pow(h, 2));
//因為如果BMI算出來是10.0000時,他要求輸出10,所以多了一個步驟判斷
//如果BMI>BMI的整數部分,代表他後面的小數點是有數字的
if(BMI > (int)Math.floor(BMI))
{
System.out.printf("%.4f", BMI);
System.out.println();
}
else
{
System.out.println((int)Math.floor(BMI));
//(int)Math.floor(BMI)可以讓浮點數變整數
}
if(BMI < 18.5)
{
System.out.print("too thin");
}
if(BMI >= 18.5 && BMI < 24)
{
System.out.print("standard");
}
if(BMI >= 24)
{
System.out.print("too fat");
}
}
}
import java.lang.*;
public class main{
public static void main(String arge[]){
double h, w;
Scanner sc = new Scanner(System.in);
h = sc.nextFloat();
w = sc.nextFloat();
double BMI;
BMI = w/(Math.pow(h, 2));
//因為如果BMI算出來是10.0000時,他要求輸出10,所以多了一個步驟判斷
//如果BMI>BMI的整數部分,代表他後面的小數點是有數字的
if(BMI > (int)Math.floor(BMI))
{
System.out.printf("%.4f", BMI);
System.out.println();
}
else
{
System.out.println((int)Math.floor(BMI));
//(int)Math.floor(BMI)可以讓浮點數變整數
}
if(BMI < 18.5)
{
System.out.print("too thin");
}
if(BMI >= 18.5 && BMI < 24)
{
System.out.print("standard");
}
if(BMI >= 24)
{
System.out.print("too fat");
}
}
}
[瘋狂程設]F019:長方形面積
import java.util.*;
public class main{
public static void main(String arge[]){
int l, w;
Scanner sc = new Scanner(System.in);
l = sc.nextInt();
w = sc.nextInt();
System.out.print(l*w);
}
}
public class main{
public static void main(String arge[]){
int l, w;
Scanner sc = new Scanner(System.in);
l = sc.nextInt();
w = sc.nextInt();
System.out.print(l*w);
}
}
[瘋狂程設]F001:兩數相加
import java.util.*;
public class main{
public static void main(String arge[]){
Scanner sc = new Scanner(System.in);
int x, y;
x = sc.nextInt();
y = sc.nextInt();
System.out.print(x+y);
}
}
public class main{
public static void main(String arge[]){
Scanner sc = new Scanner(System.in);
int x, y;
x = sc.nextInt();
y = sc.nextInt();
System.out.print(x+y);
}
}
[UVA]10055:Hashmat the brave warrior
Time
Limit: 3 sec
Description
Hashmat
is a brave warrior who with his group of young soldiers moves from one place to
another to fight against his opponents. Before fighting he just calculates one
thing, the difference between his soldier number and the opponent's soldier
number. From this difference he decides whether to fight or not. Hashmat's soldier number is never greater than his
opponent.
Input
The
input contains two integer numbers in every line. These two numbers in each line
denotes the number of soldiers in Hashmat's army and
his opponent's army or vice versa. The input numbers are not greater than 2^32.
Input is terminated by End of File.
Output
For
each line of input, print the difference of number of soldiers between Hashmat's army and his opponent's army. Each output should
be in seperate line.
Sample
Input
|
Sample
Output
|
Sample
IO Generation
|
10
12
10
14
100
200
|
2
4
100
|
計算兩軍隊的兵力差,因為"The input numbers are not greater than 2^32,所以要用long才不會溢位
import java.util.*;
public class main{
public static void main(String arge[]){
Scanner sc = new Scanner(System.in);
long x, y;
while(sc.hasNext())
{
x = sc.nextLong();
y = sc.nextLong();
System.out.println(Math.abs(x-y));
}
}
}
[UVA]10041:Vito's family
Time
Limit: 3 sec
Background
The
world-known gangster Vito Deadstone is moving to New
York. He has a very big family there, all of them living in Lamafia Avenue. Since he will visit all his relatives very
often, he is trying to find a house close to them.
Description
Vito
wants to minimize the total distance to all of them and has blackmailed you to
write a program that solves his problem.
Input
The
input consists of several test cases. The first line contains the number of test
cases.
For
each test case you will be given the integer number of relatives r ( 0 < r < 500) and the street numbers (also
integers) where they live ( 0
< si < 30000 ). Note that
several relatives could live in the same street number.
Output
For
each test case your program must write the minimal sum of distances from the
optimal Vito's house to each one of his relatives. The distance between two
street numbers si and sj is dij= |si-sj|.
Sample
Input
|
Sample
Output
|
2
2
2 4
3
2 4 6
|
2
4
|
import java.util.*;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test_time = sc.nextInt(); //輸入測試次數
for (int c=0; c<test_time; c++)
{
int[] r = new int[sc.nextInt()]; //輸入親戚數量
for (int i=0; i<r.length; i++)
{
r[i] = sc.nextInt(); //輸入親戚住在哪條街上
}
Arrays.sort(r); //排序( Array.sort() ),將號碼從小排到大
int m = r[r.length/2]; //找出陣列中點
int sum=0;
for (int i=0; i<r.length; i++)
{
sum = sum + Math.abs(r[i]-m); // Math.abs絕對值
}
System.out.println(sum);
}
}
}
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test_time = sc.nextInt(); //輸入測試次數
for (int c=0; c<test_time; c++)
{
int[] r = new int[sc.nextInt()]; //輸入親戚數量
for (int i=0; i<r.length; i++)
{
r[i] = sc.nextInt(); //輸入親戚住在哪條街上
}
Arrays.sort(r); //排序( Array.sort() ),將號碼從小排到大
int m = r[r.length/2]; //找出陣列中點
int sum=0;
for (int i=0; i<r.length; i++)
{
sum = sum + Math.abs(r[i]-m); // Math.abs絕對值
}
System.out.println(sum);
}
}
}
[瘋狂程設]A003:攝氏轉華氏
import java.util.*;
public class main{
public static void main(String[] args){
float c, f;
Scanner sc = new Scanner(System.in);
c = sc.nextInt();
f = ((c*9)/5)+32;
System.out.println("C=");
System.out.print("F="+(int)Math.floor(f));
}
}
public class main{
public static void main(String[] args){
float c, f;
Scanner sc = new Scanner(System.in);
c = sc.nextInt();
f = ((c*9)/5)+32;
System.out.println("C=");
System.out.print("F="+(int)Math.floor(f));
}
}
[瘋狂程設]A002:HelloWorld
import java.util.*;
public class main{
public static void main(String[] args){
System.out.print("Hello World!");
}
}
public class main{
public static void main(String[] args){
System.out.print("Hello World!");
}
}
[瘋狂程設]A001:HelloWorld
import java.util.*;
public class main{
public static void main(String[] args){
System.out.print("Hello World!");
}
}
public class main{
public static void main(String[] args){
System.out.print("Hello World!");
}
}
訂閱:
文章 (Atom)