일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 이분 탐색
- NEXT
- 세그먼트 트리
- 2023
- lazy propagation
- DP
- 문자열
- 가끔은_말로
- object detection
- 너비 우선 탐색
- tensorflow
- pytorch
- 백트래킹
- dropout
- back propagation
- BFS
- 회고록
- 자바스크립트
- 크루스칼
- Overfitting
- 알고리즘
- 가끔은 말로
- 미래는_현재와_과거로
- 플로이드 와샬
- 분할 정복
- 조합론
- dfs
- 우선 순위 큐
- c++
- 다익스트라
Archives
- Today
- Total
Doby's Lab
백준 12813번: 이진수 연산 (C++) 본문
https://www.acmicpc.net/problem/12813
12813번: 이진수 연산
총 100,000 비트로 이루어진 이진수 A와 B가 주어진다. 이때, A & B, A | B, A ^ B, ~A, ~B를 한 값을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
Solved By: Implementation, Bitwise Operation
비트 연산(Bitwise Operation)을 이해하기 위해 풀어본 문제였습니다.
#include <iostream>
using namespace std;
string a, b;
int main(){
cin >> a >> b;
// AND
for(int i = 0; i < a.length(); i++){
if(a[i] == '1' && b[i] == '1'){
cout << 1;
}
else cout << 0;
}
cout << '\n';
// OR
for(int i = 0; i < a.length(); i++){
if(a[i] == '1' || b[i] == '1'){
cout << 1;
}
else cout << 0;
}
cout << '\n';
// XOR
for(int i = 0; i < a.length(); i++){
if(a[i] != b[i]){
cout << 1;
}
else cout << 0;
}
cout << '\n';
// NOT a
for(int i = 0; i < a.length(); i++){
if(a[i] == '1'){
cout << 0;
}
else cout << 1;
}
cout << '\n';
// NOT b
for(int i = 0; i < a.length(); i++){
if(b[i] == '1'){
cout << 0;
}
else cout << 1;
}
cout << '\n';
return 0;
}
'PS > BOJ' 카테고리의 다른 글
백준 11280번: 2-SAT - 3 (C++) (0) | 2022.04.27 |
---|---|
백준 20504번: I번은 쉬운 문제 (C++) (1) | 2022.04.26 |
백준 11378번: 열혈강호 4 (C++) (0) | 2022.04.25 |
백준 18133번: 가톨릭대학교에 워터 슬라이드를? (C++) (0) | 2022.04.24 |
백준 1258번: 문제 할당 (C++) (0) | 2022.04.24 |