Open Teages opened 4 years ago
Code 显示测试
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;
string numstr[]={"one","two","three","four","five","six","seven",
"eight","nine","ten","eleven","twelve","thirteen",
"fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen","twenty"};
ll tennum[]={1,100,10000,1000000,100000000,10000000000};
ll num[10];
ll strtoint(string a){
for (int i=0;i<20;i++){
if(numstr[i]==a)return i+1;
}//对正规单词的判断
//下面是对特殊情况的判断
if(a=="a")return 1;
if(a=="both")return 2;
if(a=="another")return 2;
if(a=="first")return 1;
if(a=="second")return 2;
if(a=="third")return 3;
//这个单词不表示数值就return 0
return 0;
}
int main(){
string pwtmp;
ll numtmp=0;
//本来没必要开longlong的,但是不开longlong有可能导致下面计算会出玄学问题,所以还是浪费下
int numi=0;//存储句子中有多少个代表数值的单词
while(cin >> pwtmp){
if (pwtmp == ".") break;//读到句号句子结束
numtmp = strtoint(pwtmp);
if (numtmp != 0){
num[numi]=(numtmp * numtmp)%100;//根据公式计算
numi++;
}
}
sort(num,num+numi);//将数值从小到大排序
ll ans = 0;
for (int i=0;i<numi;i++){
ans =ans + num[i] * tennum[numi-i-1];
}//数学计算,手写一下很好理解
cout << ans;//输出结果,因为非数值单词都被标位0所以没必要排查
return 0;
}
https://blog.teages.xyz/pages/Luogu-p1603.html
洛谷:题目