fortyyearslater @ 2022-05-02 01:24:39
#include <bits/stdc++.h>
using namespace std;
string numbers[29]={" 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 i,a,b,c,p,sum=1;
string out,in,nums[8];
bool flag;
string number[29]={"0","01","04","09","16","25","36","49","64","81","00","21","44","69","96","25","56","89","24","61","0","01","04","01","01","04","09"};
void detect(int pos,string in)
{
for(p=0;p<=26;p++)
{
if(in.find(numbers[p])==pos)
{
flag=true;
nums[sum]=number[p];
sum++;
}
}
}
int main()
{
getline(cin,in);
for(i=0;i<in.length();i++)detect(i,in);
sum--;
sort(nums,nums+sum+1);
if(flag==false){cout<<"0";return 0;}
if(nums[1]!="0")
{
if(nums[1][0]=='0')nums[1][0]='\0';
cout<<nums[1];
for(i=2;i<=sum;i++)cout<<nums[i];
}
if(nums[1]=="0")
{
if(nums[1][0]=='0')nums[1][0]='\0';
cout<<nums[1];
if(nums[2]<"10")nums[2][0]='\0';
cout<<nums[2];
for(i=3;i<=sum;i++)cout<<nums[i];
}
return 0;
}
本地编译输入样例可过,但洛谷上WA了
by fortyyearslater @ 2022-05-02 01:50:04
已AC。
#include <bits/stdc++.h>
using namespace std;
string numbers[29]={" 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 i,p,sum=1;
string out,in;
int nums[8];
bool flag,first;
int number[29]={0,1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,1,4,1,1,4,9};
void detect(int pos,string in)
{
for(p=0;p<=26;p++)
{
if(in.find(numbers[p])==pos)
{
flag=true;
nums[sum]=number[p];
sum++;
}
}
}
int main()
{
getline(cin,in);
in=" "+in+" ";
for(i=0;i<in.length();i++)detect(i,in);
sum--;
sort(nums,nums+sum+1);
if(flag==false){cout<<"0";return 0;}
first=true;
if(nums[1]!=0)
{
for(i=1;i<=sum;i++)
{
if(nums[i]<10&&first==false)cout<<"0";
cout<<nums[i];
first=false;
}
}
if(nums[1]==0)
{
for(i=2;i<=sum;i++)
{
if(nums[i]<10&&first==false)cout<<"0";
cout<<nums[i];
first=false;
}
}
return 0;
}
by fortyyearslater @ 2022-05-02 01:52:25
WA原因:\ 字符串输出格式问题导致洛谷评测系统输出乱码
by Hisaishi_Kanade @ 2022-05-02 07:33:12
@fortyyearslater 字符串题大多都是如此