输入一串字符串,26个小写英文字母。
a,z为对称。b,y 为对称,题目让你输入对称字符对的对数。
也不知道咱写的对不对。
其实可以不用set容器。
多一点临界判断就行了。
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
using namespace std;
void nums(string& str, set<pair<char, char>>& s, vector<char>&temp)
{
int x =int( 'a' + 'z');
for (int i = 0; i < str.size(); i++)
{
temp.push_back(str[i]);
}
sort(temp.begin(), temp.end());
int l = 0, r = str.size() - 1;
while (l < r)
{
if (int(temp[l] + temp[r]) == x)
{
s.insert(make_pair(temp[l],temp[r]));
++l;
--r;
}
else if (int(temp[l] + temp[r]) <x)
{
++l;
}
else {
--r;
}
}
}
int main()
{
string str;
getline(cin,str);
set<pair<char,char>>s;
vector<char> sp;
nums(str,s,sp);
cout << s.size();
return 0;
}