题目:
解答:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
pair<int, int> parsestr(string str)
{
if (str.size() == 0)
{
return make_pair(0, 0);
}
int a = 0;
int b = 0;
string str1;
string str2;
int i = 0;
while (str[i] != ',')
{
str1.push_back(str[i]);
i++;
}
i++;
while (i<str.size())
{
str2.push_back(str[i]);
i++;
}
if (str1.size() > 0 && str2.size() && str1[0] != '0' && str2[0] != '0')
{
a = stoi(str1);
b = stoi(str2);
if (a > 0 && b > 0 && a < 1000 && b < 1000)
{
return make_pair(a, b);
}
else
{
return make_pair(0, 0);
}
}
return make_pair(0, 0);
}
vector<string> splitstr(string str)
{
vector<string> strlist;
for (int i = 0; i < str.size();)
{
string s;
while (i < str.size() && str[i] != '(' )
{
i++;
}
i++;
while (i < str.size() && str[i] != ')' )
{
s.push_back(str[i]);
i++;
}
strlist.push_back(s);
}
return strlist;
}
bool cmp(pair<int, int>a, pair<int, int>b)
{
return (a.first * a.first + a.second * a.second) > (b.first * b.first + b.second * b.second);
}
int main() {
string str;
cin >> str;
vector<string> strlist = splitstr(str);
/*for (auto it : strlist)
{
cout << it << endl;
}
*/
vector<pair<int, int> > reslist;
for (auto it: strlist)
{
reslist.push_back(parsestr(it));
}
sort(reslist.begin(), reslist.end(), cmp);
if (reslist.size() > 0 && reslist[0].first > 0 && reslist[0].second > 0)
{
cout << '(' << reslist[0].first << ',' << reslist[0].second << ')' << endl;
}
else
{
cout << "(0,0)" << endl;
}
return 0;
}