HDU 2003 求绝对值

Problem Description

求实数的绝对值。

Input

输入数据有多组,每组占一行,每行包含一个实数。

Output

对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。

Sample Input

123
-234.00

Sample Output

123.00 234.00

分析:此题考绝对值函数

AC源代码(Java语言):

import java.util.Arrays;
import java.util.Scanner;

public class Main{
//    public final static double pi = 3.1415927;
    public static void main(String[] args) {

        Scanner sin=new Scanner(System.in);
        while(sin.hasNextDouble()){
            double num = sin.nextDouble();
            num = Math.abs(num);
            String res = String.format("%.2f", num);
            System.out.println(res);
        }
    }
}

时间: 2024-07-29 00:33:17

HDU 2003 求绝对值的相关文章

2003 求绝对值

2003    求绝对值 Problem Description 求实数的绝对值. Input 输入数据有多组,每组占一行,每行包含一个实数. Output 对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数. Sample Input 123 -234.00 Sample Output 123.00 234.00 #include<stdio.h> int main() { double a; while(scanf("%lf",&a)!=E

求绝对值

求绝对值 Problem : 412 Time Limit : 1000ms Memory Limit : 65536K description 求实数的绝对值. input 输入数据有多组,每组占一行,每行包含一个实数. output 对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数. sample_input 123 -234.00 sample_output 123.00 234.00 hint   source hdu #include <stdio.h> #i

HDU 4006 求第k大数 treap

裸题,瞬秒.. #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include <vector> #include <set> #include <map> #include <queue> using namespace std; #define L(id) tree[id].ch[0] #defin

无符号类型赋值负数,以及求绝对值

#include <iostream> #include <cmath> int main() { unsigned char i = 0 ; i = -1 ; std::cout<<"i="<<(int)i<<std::endl; i = -2 ; std::cout<<"i="<<(int)i<<std::endl; i = -3 ; std::cout<<

HDU 2485 求删最少点使得 边权=1的有向图最短路&gt;k

题意: 给定n个点 m条有向边 k 下面m条有向边 问删最少几个点使得1-n的最短路>k 10 11 5 1 2 2 3 3 4 4 5 5 10 2 9 1 6 6 7 7 8 8 9 9 10 8 10 5 1 2 2 3 3 4 4 5 5 6 6 8 1 7 7 8 4 7 7 4 #include <stdio.h> #include <string.h> #define N 55 #define INF 1<<30 #define eps 1e-5 i

python常用函数之--求绝对值函数:abs(x)

python中的求绝对值函数:abs(X) 1. 参数 x 可以是整形也可以是复数,假如是复数的话,就求复数的模. >>> # 整形数字 ... >>> a = 10 >>> b = -100 >>> a 10 >>> b -100 >>> abs(a) 10 >>> a 10 >>> abs(b) 100 >>> b -100 >>

【c语言】求绝对值

// 求绝对值 #include <stdio.h> int fabs(int a) { if (a < 0) { a = ~a + 1; } return a; } int main() { printf("绝对值是:%d\n", fabs(5)); printf("绝对值是:%d\n", fabs(0)); printf("绝对值是:%d\n", fabs(-1)); return 0; } 版权声明:本文为博主原创文章,未

Java练习 SDUT-1117_求绝对值(选择结构)

C语言实验--求绝对值(选择结构) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 从键盘上输入任意一个整数,然后输出它的绝对值! Input 从键盘上输入任意一个整数. Output 输出它的绝对值. Sample Input -4 Sample Output 4 超级水题 import java.util.*; public class Main { public static void main(String[

hdu 5105 求函数极值 函数求导/三分法

http://acm.hdu.edu.cn/showproblem.php?pid=5105 给定a,b,c,d,l,r,表示有一个函数f(x)=|a?x3+b?x2+c?x+d|(L≤x≤R),求函数最大值. 考虑极点可能有0~2个.在极值点处函数的单调性会发生变化,所以最大值一定就在区间边界和极值点上.所以求下l,r,极值点的函数大小然后取最大的即可. #include <cstdio> #include <cstdlib> #include <cmath> #in