using System;
using System.Collections.Generic;
class NonRepeatedCharacter
{
static void Main()
{
string str = "ppdadxefe";
char? result = FindFirstNonRepeatedChar(str);
Console.WriteLine(result.HasValue ? $"First non-repeated character: {result}" : "No non-repeated character found.");
}
static char? FindFirstNonRepeatedChar(string str) {
var charCount = new Dictionary<char, int>();
foreach (char ch in str) {
if (charCount.ContainsKey(ch))
charCount[ch]++;
else
charCount[ch] = 1;
}
foreach (char ch in str) {
if (charCount[ch] == 1)
return ch;
}
return null;
}
}
/*
run:
First non-repeated character: a
*/