Eat_A_HuTao @ 2019-11-02 11:45:13
#include <bits/stdc++.h>
using namespace std;
int a[20];
int k(string n)
{
if(n=="a" || n=="one" || n=="first")
return 1;
if(n=="both" || n=="second" || n=="two")
return 4;
if(n=="another" || n=="third" || n=="three")
return 9;
if(n=="four")
return 16;
if(n=="five")
return 25;
if(n=="six")
return 36;
if(n=="seven")
return 49;
if(n=="eight")
return 64;
if(n=="nine")
return 81;
if(n=="ten")
return 0;
if(n=="eleven")
return 21;
if(n=="twelve")
return 44;
if(n=="thirteen")
return 69;
if(n=="fourteen")
return 96;
if(n=="fifteen")
return 25;
if(n=="sixteen")
return 56;
if(n=="seventeen")
return 89;
if(n=="eighteen")
return 24;
if(n=="nineteen")
return 61;
if(n=="twenty")
return 0;
}
int main()
{
for(int i=1;i<=14;i++)
{
string c;
cin>>c;
a[i]=k(c);
}
sort(a+1,a+20);
for(int i=1;i<=8;i++)
if(a[i]!=0)
cout<<a[i];
}
by ztxtjz @ 2019-11-02 12:04:15
首先只有六个单词,其次不能用sort,不是数字小的排在前面就小,比如9和16肯定是169小
by Eat_A_HuTao @ 2019-11-03 11:29:35
@ztxtjz 那样例不应该是254吗?
by Eat_A_HuTao @ 2019-11-03 14:56:36
#include <bits/stdc++.h>
using namespace std;
int a[7],s=1,ans;
int k(string n)
{
if(n=="a" || n=="one" || n=="first")
{
s++;
return 1;
}
if(n=="both" || n=="second" || n=="two")
{
s++;
return 4;
}
if(n=="another" || n=="third" || n=="three")
{
s++;
return 9;
}
if(n=="four")
{
s++;
return 16;
}
if(n=="five")
{
s++;
return 25;
}
if(n=="six")
{
s++;
return 36;
}
if(n=="seven")
{
s++;
return 49;
}
if(n=="eight")
{
s++;
return 64;
}
if(n=="nine")
{
s++;
return 81;
}
if(n=="ten")
{
s++;
return 0;
}
if(n=="eleven")
{
s++;
return 21;
}
if(n=="twelve")
{
s++;
return 44;
}
if(n=="thirteen")
{
s++;
return 69;
}
if(n=="fourteen")
{
s++;
return 96;
}
if(n=="fifteen")
{
s++;
return 25;
}
if(n=="sixteen")
{
s++;
return 56;
}
if(n=="seventeen")
{
s++;
return 89;
}
if(n=="eighteen")
{
s++;
return 24;
}
if(n=="nineteen")
{
s++;
return 61;
}
if(n=="twenty")
{
s++;
return 0;
}
}
int main()
{
string c;
for (int i=0;i<6;i++)
{
cin>>c;
a[s]=k(c);
}
cin>>c;
sort(a+1,a+s+1);
for(int i=2;i<=s;i++)
{
ans+=a[i];
ans*=100;
}
cout<<ans/100;
}
我改了一下,还有一个点不对
by 刘安哲 @ 2019-12-04 18:47:06
@神剑 样例的3个数是00,04,25,把4接到25后面的话应该是2504
by Eat_A_HuTao @ 2019-12-10 16:16:20
@刘安哲 好谢谢,题目已过