#include <iostream>
#include <vector>
#include <string>
int main() {
std::string s = "ADARSH"; // Example string
std::vector<int> charIndex(128, -1); // 128 for ASCII characters, initialized to -1
// Iterate over the string and store the first occurrence of each character
for (int i = 0; i < s.length(); i++) {
char currentChar = s[i];
int asciiValue = (int)currentChar; // Get ASCII value
// Store the first occurrence only if it's not already stored
if (charIndex[asciiValue] == -1) {
charIndex[asciiValue] = i;
}
}
// Print the characters in the order they appear in the string, but only the first occurrence
std::cout << "Character\tASCII Value\tFirst Occurrence Index" << std::endl;
for (int i = 0; i < s.length(); i++) {
char currentChar = s[i];
int asciiValue = (int)currentChar;
// If it's the first occurrence, print it
if (charIndex[asciiValue] == i) {
std::cout << currentChar << "\t\t" << asciiValue << "\t\t" << i << std::endl;
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: