@[Dcchen](/user/1012241)
本地运行输入完的时候要ctrl+z
单词表的50写错了
意义不明的 $\times 10$
意义不明的continue
帮你改了
```cpp
#include<iostream>
#include<string.h>
using namespace std;
const string a[28]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
//50 fifteen->fifty
const int b[28]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90};
string st;
int ans,sum,flag=1;
int main(){
while(cin>>st){
if(st=="negative")
flag=0;
for(int i=0;i<28;i++){
if(st==a[i]){
sum+=b[i];//sum=sum*10+b[i]->sum+=b[i]
break;//continue->break
}
}
if(st=="hundred")
sum*=100;
else if(st=="thousand")
sum*=1000;
else if(st=="million")
sum*=10000;
//ans+=sum,sum=0->
}
ans+=sum;
flag?cout<<ans:cout<<0-ans;;
return 0;
}
```
by liaiyang @ 2023-09-02 18:44:45
说实话倒数第三行好像也没啥用(((
by liaiyang @ 2023-09-02 18:45:59
。。。楼上的代码似乎还是不对
1.50拼写
2.100的处理
3.million不是10000
坑!!!
AC代码:
```
#include<iostream>
#include<string.h>
using namespace std;
#define int long long
const string a[28]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
const int b[28]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90};
string st;
int ans,sum,flag=1;
signed main(){
hbr: while(cin>>st){
if(st=="negative"){
flag=0;
continue;
}
for(int i=0;i<28;i++){
if(st==a[i]){
sum+=b[i];
goto hbr;
}
}
if(st=="hundred"){
sum*=100;
goto hbr;
}
if(st=="thousand")sum*=1000;
else if(st=="million")sum*=1000000;
ans+=sum,sum=0;
}
ans+=sum;
flag?cout<<ans:cout<<0-ans;;
return 0;
}
by Null_h @ 2023-09-02 18:53:36
@[Dcchen](/user/1012241)
by Null_h @ 2023-09-02 18:53:46
@[liaiyang](/user/783170) 感谢大佬
by Dcchen @ 2023-09-02 20:32:30
@[kdqs8218](/user/705712) 感谢大佬
by Dcchen @ 2023-09-02 20:32:53
@[kdqs8218](/user/705712) 讲一下hbr: 和 goto hbr;的意思好吗?
by Dcchen @ 2023-09-02 20:50:21
@[liaiyang](/user/783170) 您的代码只有48分
by Dcchen @ 2023-09-02 20:57:10
@[Dcchen](/user/1012241) 直接跳转到某一行
by Null_h @ 2023-09-02 21:40:12
你不是说kdqs8218
最后在线时间:2023年9月2日19时30分吗?不过很感谢你
by Dcchen @ 2023-09-03 10:00:25