※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 11104번 문제인 Fridge of Your Dreams이다.
문제는 아래 링크를 확인하자.

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

 

11104번: Fridge of Your Dreams

Eirik drinks a lot of Bingo Cola to help him program faster, and over the years he has burned many unnecessary calories walking all the way to the kitchen to get some. To avoid this he has just bought a small fridge, which is beautifully placed next to his

www.acmicpc.net

각 테스트케이스마다 주어지는 이진수를 십진수로 바꾸어 출력하는 문제이다.

 

이진수를 표현하는 주어진 문자열의 각 자릿수를 살펴 직접 십진수로 바꿀 수도 있지만, string 헤더의 stoi 함수를 이용하면 위 작업을 함수 하나로 간단히 해낼 수 있다. stoi 함수는 십진수를 표현한 문자열이 아닌 다른 진법에도 적용할 수 있다는 점을 알아두자.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T; cin >> T;
	while (T--) {
		string s; cin >> s;
		cout << stoi(s, nullptr, 2) << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 6970 // C++] Sentences  (0) 2022.08.28
[BOJ 14646 // C++] 욱제는 결정장애야!!  (0) 2022.08.28
[BOJ 17612 // C++] 쇼핑몰  (0) 2022.08.26
[BOJ 2635 // C++] 수 이어가기  (0) 2022.08.25
[BOJ 2636 // C++] 치즈  (0) 2022.08.24

+ Recent posts