CPP
cpp
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
// Created by WindSeaVT
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a[100];
cout << "Nhap: ";
cin >> a; // Read input (no spaces allowed)
int len = strlen(a);
for (int i = 0; i < len; i++) {
bool alreadyCounted = false;
// Check if the character is already processed
for (int j = 0; j < i; j++) {
if (a[i] == a[j]) {
alreadyCounted = true;
break;
}
}
if (!alreadyCounted) {
// Count occurrences of the character
int count = 1;
for (int j = i + 1; j < len; j++) {
if (a[i] == a[j]) count++;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run