华为机试输出指定字母在字符串的中的索引)
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
char findk(string s, int k) {
sort(s.begin(), s.end());
return s[k - 1];
}
int main() {
string s;
int k = 0;
cin >> s>>k;
char target = findk(s,k);
for (int i = 0; i < s.size(); ++i) {
if (s[i] == target) {
cout << i << endl;
return 0;
}
}
}
标签:int,字母,char,索引,字符串,include
From: https://www.cnblogs.com/chunbai11/p/16747731.html