Print the First Non Repeated Character | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Print the First Non Repeated Character

Get the input string from the user and print the first non repeating character in the string. if there is no Non repeating character print 0. For Example input : Hello result: H input : xxyyzz result: 0

26th Apr 2018, 10:42 AM
Ajith
Ajith - avatar
1 Respuesta
+ 1
char in, cmp{'\0'}; bool repeated{false}; while (std::cin >> in) { if (in == cmp) repeated = true; if (!repeated && in != cmp) { std::cout << in; break; } else { cmp = in; repeated = false; } }
26th Apr 2018, 11:02 AM
Timon Paßlick