syman_liu @ 2024-01-13 13:09:01
各位大佬,本蒟蒻又来请教问题了
P1603 80分 #4 WA,原因:
too short on line 1
代码如下
#include <bits/stdc++.h>
using namespace std;
string num1[25] = {"","one","two","three","four","five","six ","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
string num2[5] = {"","a","another","first"};
string num3[5] = {"","both","second"};
string num4 = "third";
int ans[10];
int main()
{
int cnt = 0;
for (int i = 1;i <= 6;i ++)
{
string s;
cin >> s;
for (int j = 1;j <= 20;j ++)
{
if (s == num1[j]) ans[++ cnt] = j;
}
for (int j = 1;j <= 3;j ++)
{
if (s == num2[j]) ans[++ cnt] = 1;
}
for (int j = 1;j <= 3;j ++)
{
if (s == num3[j]) ans[++ cnt] = 2;
}
if (s == num4) ans[++ cnt] = 3;
}
if (cnt == 0)
{
cout << 0 << endl;
return 0;
}
for (int i = 1;i <= cnt;i ++)
{
ans[i] = ans[i] * ans[i] % 100;
}
sort(ans + 1,ans + cnt + 1);
for (int i = 1;i <= cnt;i ++)
{
if (i != 1 and ans[i] < 10) cout << 0;
cout << ans[i];
}
return 0;
}
谢谢各位大佬!
by timmyliao @ 2024-01-13 13:25:32
AC(经供参考)
#include<bits/stdc++.h>
using namespace std;
char dic[30][20]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty","a","both","another","first","second","third"};//对应
int di[30]={0,1,4,9,16,25,36,49,64,81,00,21,44,69,96,25,56,89,24,61,0,1,4,1,1,4,9};
unsigned long long int a[10],top,flag;
int i,j;
char s[100];
int main()
{
for(i=1;i<=6;i++)
{
scanf("%s",&s);//%s读入遇到空格就停止
for(j=1;j<=26;j++)
{
if(!strcmp(s,dic[j]))//strcmp(s1,s2);如果他们相同,返回0
{
a[++top]=di[j];//用数组存储
break;//立即停止寻找
}
}
}
sort(a+1,a+top+1);//贪心,使越小的数越靠前输出
for(i=1;i<=top;i++)
{
if(flag)//如果不是第一位
{
printf("%.2d",a[i]);//限制格式输出
}
else
{
if(a[i])
{
printf("%d",a[i]);
flag=1;
}
}
}
if(!flag)printf("0");//特判
return 0;
}
by syman_liu @ 2024-01-13 15:55:41
@timmyliao
感谢回复!
我有一个问题:zero需要处理吗?
by timmyliao @ 2024-01-13 16:31:15
@syman_liu 需要的
if(!flag)printf("0");//特判