-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkstring.cc
More file actions
55 lines (44 loc) · 779 Bytes
/
kstring.cc
File metadata and controls
55 lines (44 loc) · 779 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<string>
#include<algorithm>
#include<cstddef>
using namespace std;
int main(){
int k;
scanf("%d",&k);
string s;
cin.ignore();
getline(cin,s);
string m = "";
size_t found = s.find_first_not_of(m);
while(found != string::npos){
m.push_back(s[found]);
found = s.find_first_not_of(m,found+1);
}
string n;
//cout<<m<<"\n";
bool a = true;
for(int i = 0;i<k;i++){
for(int j=0;j<m.size();j++){
found = s.find_first_of(m[j]);
if(found == string::npos){
a =false;
break;
}
//cout<<s[found]<<"\n";
//cout<<*(s.begin() + found)<<"\n";
n.push_back(s[found]);
s.erase(s.begin() + found);
}
if(a == false){
break;
}
}
if(a == false){
cout<<"-1";
}
else{
cout<<n;
}
return 0;
}