일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 악성코드
- function
- Kafka
- 노드
- CSS
- C
- jsp
- windows
- Call-by-reference
- algorithm
- 포인터
- WebProgramming
- 투자
- UTF-8
- Sort
- beans
- meta
- JavaScript
- OOP
- request
- 자료구조
- CLASS
- query
- array
- java
- 윈도우즈
- System
- HTML
- API
- c++
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 |
Comments