일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- CLASS
- request
- query
- 노드
- windows
- 투자
- 악성코드
- Kafka
- UTF-8
- array
- C
- WebProgramming
- algorithm
- 포인터
- HTML
- JavaScript
- java
- Sort
- jsp
- OOP
- API
- meta
- CSS
- Call-by-reference
- 윈도우즈
- function
- 자료구조
- c++
- System
- beans
Archives
- Today
- Total
hahahia
c++ string을 이용한 2진수에서 10진수 변환 프로그램 본문
/*
made by hahahia
main.cpp */
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <string>
using namespace std;
int main(){
int result = 0;
string str;
cin >> str;
int e=1;
for(int i=str.length()-1; i>=0; i--)
{
for(int j=0; j<str.length()-i-1; j++)
e*=2;
if(str[i] == '1')
result += e;
e=1;
}
cout << result << endl;
return 0;
}
출력 결과
0011
3
1001
9
1100
12
'Algorithm' 카테고리의 다른 글
Heap Sort(힙 정렬) 구현 (2) | 2012.11.13 |
---|---|
binary search(이진 탐색) (0) | 2012.10.04 |
더블릿 문제풀이(최대 구간 구하기) (0) | 2012.10.04 |
쉬프트 연산( << , >> ) (0) | 2012.09.01 |
Selection Sort(선택 정렬) (2) | 2012.04.06 |