※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26590번 문제인 Word Mix이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26590
26590번: Word Mix
Write a program that will combine two words into a new one. The length of the two words will be unknown. The new word will be the same length as the shorter word. The letters at even indexes will be taken from the first word at the corresponding indexes an
www.acmicpc.net
두 문자열중 짧은 길이만큼 짝수번째 문자는 첫번째 문자열에서, 홀수번째 문자는 두번째 문자열에서 뽑아 출력해 문제를 해결하자.
이 문제에서 홀수번째와 짝수번째는 0-based index로 주어져있음에 유의하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int N;
string s1, s2;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s1 >> s2;
N = min(s1.length(), s2.length());
for (int i = 0; i < N; i++) {
if (i & 1) cout << s2[i];
else cout << s1[i];
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 6843 // C++] Anagram Checker (0) | 2022.12.22 |
---|---|
[BOJ 5344 // C++] GCD (0) | 2022.12.22 |
[BOJ 16911 // C++] 그래프와 쿼리 (0) | 2022.12.22 |
[BOJ 26564 // C++] Poker Hand (0) | 2022.12.21 |
[BOJ 26533 // C++] Tractor Path (0) | 2022.12.21 |