关于开不开O2优化
查看原帖
关于开不开O2优化
791514
morgan2022楼主2024/10/3 20:41

有没有大佬告诉我为什么这道题开了优化就30,不开就AK?

#include<bits/stdc++.h>
using namespace std;
#define int long long
string en[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string en1[10]={"zero","","twenty ","thirty ","fourty ","fifty ","sixty ","seventy ","eighty ","ninety "};
string en2[10]={"ten","eleven","twleve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
signed main(){
    int n,c=4;
    cin>>n;
    if(!n){cout<<"zero";return 0;}
    int k[4]={0};
    while(n){
        int h=n%10;
        k[c]=h;
        n=n/10;
        c--;
    }
    if(k[1])cout<<en[k[1]]<<" thousand ";
    if(k[2])cout<<en[k[2]]<<" hundred ";
    if(k[1]&&k[3]&&(!k[2]))cout<<"and ";
    if(k[3]&&k[3]!=1)cout<<en1[k[3]];
    if(((k[1]||k[2])&&(!k[3])&&k[4])||((k[4]&&(!k[3]))||(k[4]==0&&k[3]==1))&&(k[1]||k[2]))cout<<"and ";
    if(k[4]==0&&k[3]==1){
        cout<<"ten"<<" ";
    }
    if(k[4]){
        if(k[3]==1)cout<<en2[k[4]]<<" "<<endl;
        else cout<<en[k[4]]<<" "<<endl;
    }
	return 0;
}
2024/10/3 20:41
加载中...