BDCYI @ 2024-10-14 13:57:52
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
vector<string> vs;
vs = { "0", "one", "two", "three", "four", "five", "six","seven", "eight"
, "nine", "ten", "eleven", "twelve","thirteen","fourteen","fifteen","sixteen"
, "seventeen","eighteen","nineteen","twenty" };
map<string, int> m;
for (int i = 1; i <= vs.size() - 1; i++)
{
m[vs[i]] = i;
}
vector<int> v;
while (true)
{
cin >> s;
if (s == ".")
break;
if (m.find(s) != m.end())
v.push_back(m[s]);
}
if (v.size() == 0)
{
cout << 0;
return 0;
}
for (auto& i : v)
{
i = (i * i) % 100;
}
sort(v.begin(), v.end());
string t, s2;
for (int i : v)
{
if (i < 10)
{
t = "0" + to_string(i);
s2 += t;
}
else
s2 += to_string(i);
}
while (s2 != "0" && s2[0] == '0')
s2 = s2.substr(1);
cout << s2;
}
by BDCYI @ 2024-10-14 13:59:51
现在只能过三个60分 过不了2和5
by lyh0217 @ 2024-10-14 14:56:15
@BDCYI
非正规的单词没处理
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
vector<string> vs;
vs = { "0", "one", "two", "three", "four", "five", "six","seven", "eight"
, "nine", "ten", "eleven", "twelve","thirteen","fourteen","fifteen","sixteen"
, "seventeen","eighteen","nineteen","twenty" };
map<string, int> m;
for (int i = 1; i <= vs.size() - 1; i++)
{
m[vs[i]] = i;
}
m["a"]=1;
m["both"]=2;
m["another"]=1;
m["second"]=2;
m["first"]=1;
m["third"]=3;
vector<int> v;
while (true)
{
cin >> s;
if (s == ".")
break;
if (m.find(s) != m.end())
v.push_back(m[s]);
}
if (v.size() == 0)
{
cout << 0;
return 0;
}
for (auto& i : v)
{
i = (i * i) % 100;
}
sort(v.begin(), v.end());
string t, s2;
for (int i : v)
{
if (i < 10)
{
t = "0" + to_string(i);
s2 += t;
}
else
s2 += to_string(i);
}
while (s2 != "0" && s2[0] == '0')
s2 = s2.substr(1);
cout << s2;
}
by BDCYI @ 2024-10-14 15:54:41
@lyh0217 十分感谢