※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26416번 문제인 New Password이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26416
26416번: New Password
The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case consists of two lines. The first line of each test case contains an integer $N$, denoting the length of the old password. The second line of each test ca
www.acmicpc.net
영어 대문자, 영어 소문자, 숫자, 특수문자가 주어진 문자열에 존재하는지는 각각 확인한 뒤 없는 종류의 문자를 문자열의 뒤에 하나씩 추가해주자.
위의 처리를 완료한 뒤에 주어진 문자열의 길이가 7보다 작다면 길이가 7이 될 때까지 아무 문자나 더 추가해 문제의 조건을 만족하는 문자열을 항상 생성할 수 있다.
위의 내용을 구현해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int T;
int slen;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
for (int t = 1; t <= T; t++) {
cin >> slen >> s;
bool upper = 0, lower = 0, num = 0, schar = 0;
for (auto& l : s) {
if ('A' <= l && l <= 'Z') upper = 1;
else if ('a' <= l && l <= 'z') lower = 1;
else if ('0' <= l && l <= '9') num = 1;
else schar = 1;
}
if (!upper) s += 'A';
if (!lower) s += 'a';
if (!num) s += '0';
if (!schar) s += '#';
while (s.length() < 7) s += '#';
cout << "Case #" << t << ": " << s << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26645 // C++] 성장의 비약 선택권 (0) | 2022.12.26 |
---|---|
[BOJ 26009 // C++] 험난한 등굣길 (0) | 2022.12.26 |
[BOJ 9907 // C++] ID (0) | 2022.12.26 |
[BOJ 26743 // C++] Oczko (0) | 2022.12.25 |
[BOJ 26766 // C++] Serca (0) | 2022.12.25 |