Character Checker
Author: Pakin Olanraktham & Black Cat
Source: PROGRAMMING.IN.TH
Difficulty: Very Easy
Tags: Implementation
Prerequisites:
เฉลย
เฉลย
เราสามารถตรวจสอบตัวอักษรภายในสายอักขระทีละ 1 ตัวได้ ว่าเป็นตัวพิมพ์ใหญ่ หรือตัวพิมพ์เล็ก และทันทีที่เราพบว่ามีทั้งตัวพิมพ์ใหญ่และตัวพิมพ์เล็กในสายอักขระ เราสามารถแสดงผล "Mix" และจบโปรแกรมได้ทันที ถ้าไม่พบก็ตรวจสอบต่อไปจนจบสายอักขระ
โค้ด
#include <stdio.h>
#include <string.h>
int main() {
char t[10001];
bool lower = false, upper = false;
scanf("%s", t);
for (int i = 0; i < strlen(t); i++){
if (t[i] >= 'A' && t[i] <= 'Z') upper = true;
else lower = true;
if (lower && upper) {printf("Mix"); return 0;}
}
if (lower) printf("All Small Letter");
else printf("All Capital Letter");
}
#include <iostream>
using namespace std;
int main() {
string t;
bool lower = false, upper = false;
cin >> t;
for (int i = 0; i < t.size(); i++){
if (t[i] >= 'A' && t[i] <= 'Z') upper = true;
else lower = true;
if (lower && upper) {cout << "Mix"; return 0;}
}
if (lower) cout << "All Small Letter";
else cout << "All Capital Letter";
}