문제
https://www.acmicpc.net/problem/6887
6887번: Squares
Gigi likes to play with squares. She has a collection of equal-sized square tiles. Gigi wants to arrange some or all of her tiles on a table to form a solid square. What is the side length of the largest possible square that Gigi can build? For example, wh
www.acmicpc.net
해결방법
입력받은 숫자를 sqrt 함수를 이용하여 제곱근을 구하고 앞에 (int)를 붙여 정수로 만들어 출력하면 된다.
코드
#include<iostream>
#include<cmath>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
cout << "The largest square has side length "<<(int)sqrt(n)<<'.';
return 0;
}
'PS > Baekjoon' 카테고리의 다른 글
[C++] 백준 6825: Body Mass Index (0) | 2023.05.14 |
---|---|
[C++] 백준 25784: Easy-to-Solve Expressions (0) | 2023.05.13 |
백준 18698: The Walking Adam (0) | 2023.05.11 |
[C++] 백준 5300: Fill the Rowboats! (0) | 2023.05.10 |
[C++] 백준 5357: Dedupe (0) | 2023.05.09 |
댓글