#include <iostream> #define CHAR_TO_INT(c) (c - 'a' + 1) int main(int argc, char** argv) { std::string strInput; std::cout << "Get any string:\t"; std::cin >> strInput; int count = 0; for (int i = 0; i < strInput.length(); i++) { int val = CHAR_TO_INT(strInput[i]); if ((count & (1 << val)) > 0) { std::cout << "Input string has first non-uniques character \t" << strInput[i]; break; } count |= (1 << val); } return 0; }
Click like and share to be connected with us @ Facebook.
A place where we love to share and discuss hottest technologies, innovations and researches around.
Print first repeating character of input string in C++ : Memory Optimized
Labels:
C++