Keinez @ 2024-10-09 20:51:34
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
#include<ctype.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
string tmp;
char str[1000005] = { '\0' };
map<string, int> mp;
int digi = 0;
int arr[8] = { 0 };
int compare_ints(const void* a, const void* b) {
int arg1 = *(const int*)a;
int arg2 = *(const int*)b;
return (arg1 > arg2) - (arg1 < arg2);
}
int main()
{
mp.insert(make_pair("one", 1));
mp.insert(make_pair("a", 1));
mp.insert(make_pair("another", 1));
mp.insert(make_pair("first", 1));
mp.insert(make_pair("two", 2));
mp.insert(make_pair("both", 2));
mp.insert(make_pair("second", 2));
mp.insert(make_pair("three", 3));
mp.insert(make_pair("third", 3));
mp.insert(make_pair("four", 4));
mp.insert(make_pair("five", 5));
mp.insert(make_pair("six", 6));
mp.insert(make_pair("seven",7));
mp.insert(make_pair("eight", 8));
mp.insert(make_pair("nine", 9));
mp.insert(make_pair("ten", 10));
mp.insert(make_pair("eleven", 11));
mp.insert(make_pair("twelve", 12));
mp.insert(make_pair("thirteen", 13));
mp.insert(make_pair("fourteen", 14));
mp.insert(make_pair("fifteen", 15));
mp.insert(make_pair("sixteen", 16));
mp.insert(make_pair("seventeen", 17));
mp.insert(make_pair("eighteen", 18));
mp.insert(make_pair("nineteen", 19));
mp.insert(make_pair("twenty", 20));
mp.insert(make_pair("One", 1));
mp.insert(make_pair("A", 1));
mp.insert(make_pair("Another", 1));
mp.insert(make_pair("First", 1));
mp.insert(make_pair("Two", 2));
mp.insert(make_pair("Both", 2));
mp.insert(make_pair("Second", 2));
mp.insert(make_pair("Three", 3));
mp.insert(make_pair("Third", 3));
mp.insert(make_pair("Four", 4));
mp.insert(make_pair("Five", 5));
mp.insert(make_pair("Six", 6));
mp.insert(make_pair("Seven", 7));
mp.insert(make_pair("Eight", 8));
mp.insert(make_pair("Nine", 9));
mp.insert(make_pair("Ten", 10));
mp.insert(make_pair("Eleven", 11));
mp.insert(make_pair("Twelve", 12));
mp.insert(make_pair("Thirteen", 13));
mp.insert(make_pair("Fourteen", 14));
mp.insert(make_pair("Fifteen", 15));
mp.insert(make_pair("Sixteen", 16));
mp.insert(make_pair("Seventeen", 17));
mp.insert(make_pair("Eighteen", 18));
mp.insert(make_pair("Nineteen", 19));
mp.insert(make_pair("Twenty", 20));
fgets(str, sizeof(str), stdin);
for (int i = 0; i < strlen(str); i++)
{
if (isalpha(str[i]))
tmp += str[i];
else
{
if (tmp.size())
{
if (mp.count(tmp))
{
arr[digi] = (mp[tmp] * mp[tmp]) % 100;
digi++;
}
}
tmp = "";
}
}
qsort(arr, digi, sizeof(arr[0]), compare_ints);
unsigned long long x = 0;
for (int i = 0; i < digi-1; i++)
{
x += arr[i] * pow(10, 2*digi - (i+1) * 2);
}
printf("%llu", x);
return 0;
}
为什么最后一个测试点说wrong answer too long on line 1.
by aszxqw @ 2024-10-12 14:54:47
#include<bits/stdc++.h>
using namespace std;
const int N=50;
int st[N];
map<string,int> mp;
int main(){
mp["one"]=1,mp["two"]=2,mp["three"]=3,mp["four"]=4,mp["five"]=5,mp["six"]=6,mp["seven"]=7,mp["eight"]=8,mp["nine"]=9,mp["ten"]=10,mp["eleven"]=11,mp["twelve"]=12,mp["thirteen"]=13,mp["fourteen"]=14,mp["fifteen"]=15,mp["sixteen"]=16,mp["seventeen"]=17,mp["eighteen"]=18,mp["nineteen"]=19,mp["twenty"]=20,mp["a"]=1,mp["second"]=2,mp["third"]=3,mp["both"]=2,mp["another"],mp["first"]=1;
string s;
int t=0;
for(int i=1;i<=6;i++){
cin>>s;
int x=mp[s];
if(x){
int k=(x*x)%100;
if(k==0) continue;
st[++t]=k;
}
}
sort(st+1,st+t+1);
cout<<st[1];
for(int i=2;i<=t;i++){
if(st[i]<10)cout<<0;
cout<<st[i];
}
return 0;
}