fork download
  1. #include <iostream>
  2. #include <limits>
  3. #include <bitset>
  4.  
  5. int main()
  6. {
  7. constexpr char cstr[] = "introduction";
  8.  
  9. std::bitset< std::numeric_limits<unsigned char>::max() + 1 > present ;
  10. std::bitset< std::numeric_limits<unsigned char>::max() + 1 > repeating ;
  11. for( unsigned char u : cstr )
  12. {
  13. repeating[u] = present[u] ;
  14. present[u] = true ;
  15. }
  16.  
  17. for( unsigned char u : cstr ) if( present[u] && !repeating[u] && u != 0 )
  18. {
  19. std::cout << "first non-repeating char is '" << char(u) << "'\n" ;
  20. break ;
  21. }
  22. }
  23.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
first non-repeating char is 'r'