[백준 29108] Логины (C#, C++) - soo:bak
작성일 :
문제 링크
설명
문자열이 io로 시작하고 그 뒤가 모두 숫자인지 판정하는 문제입니다.
접근법
길이가 최소 3 이상이고, 앞 두 문자가 io인지 확인합니다. 이후 세 번째 문자부터 끝까지 모두 숫자인지 검사하여, 모든 조건을 만족하면 Correct, 아니면 Incorrect를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
class Program {
static void Main() {
var s = Console.ReadLine()!;
var ok = s.Length >= 3 && s[0] == 'i' && s[1] == 'o';
if (ok) {
for (var i = 2; i < s.Length; i++) {
if (!char.IsDigit(s[i])) { ok = false; break; }
}
}
Console.WriteLine(ok ? "Correct" : "Incorrect");
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
bool ok = s.size() >= 3 && s[0] == 'i' && s[1] == 'o';
if (ok) {
for (int i = 2; i < (int)s.size(); i++) {
if (!isdigit(s[i])) { ok = false; break; }
}
}
cout << (ok ? "Correct" : "Incorrect") << "\n";
return 0;
}