-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathch-1.cpp
More file actions
25 lines (24 loc) · 675 Bytes
/
ch-1.cpp
File metadata and controls
25 lines (24 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
int main( ) {
std::cout << "Please enter a string!\n" ;
std::string input ;
getline( std::cin , input ) ;
std::map<std::string , int> frequencies ;
int len = input.length( ) ;
for ( int i = 0 ; i < len ; i++ ) {
frequencies[ input.substr( i , 1 )]++ ;
}
std::vector<int> findPositions ;
for ( const auto & p : frequencies ) {
if ( p.second == 1 ) {
findPositions.push_back( static_cast<int>( input.find( p.first ))) ;
}
}
std::cout << *std::min_element( findPositions.begin( ) , findPositions.end( ) ) <<
std::endl ;
return 0 ;
}