반응형

백준 16486번 운동장 한 바퀴 풀이 코드

C | C++ | Java | Python


풀이

구하는 답은 '(사각형 가로) * 2 + 2 * pi * (원 반지름)'입니다. 즉, d1*2 + 2*pi*d2를 소수점 아래 6자리까지 출력하면 됩니다. C++은 cout<<fixed, cout.precision(6)로 소수점 아랫 자릿수를 고정합니다.

코드

#include <stdio.h>

int main(){
    int d1, d2;
    float pi = 3.141592;
    scanf("%d %d", &d1, &d2);
    printf("%f", (float)d1*2 + 2*pi*(float)d2);
    return 0;
}
#include <iostream>
using namespace std;

int main(){
    int d1, d2;
    float pi = 3.141592;
    cin>>d1>>d2;
    cout << fixed;
    cout.precision(6);
    cout<<d1*2 + 2*pi*d2;
    return 0;
}
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d1 = sc.nextInt(), d2 = sc.nextInt();
        double pi = 3.141592;
        System.out.println(d1*2 + 2*pi*d2);
    }
}
d1 = int(input())
d2 = int(input())
pi = 3.141592
print(d1*2 + 2*pi*d2)

문제 출처

https://www.acmicpc.net/problem/16486

반응형

+ Recent posts