3 条题解

  • 0
    @ 2025-5-6 22:38:14

    介绍两种做法: 1.数组打表

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5,INF=0x3f3f3f3f;
    typedef long long LL;
    int a,b;
    string ans[]={"","one","two","three","four","five","six","seven","eight","nine","None"};
    int main(){
    	cin>>a>>b;
    	if(a+b>0&&a+b<10)cout<<ans[a+b];
    	else cout<<ans[10];
    	return 0;
    }
    

    2.switch-case

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5,INF=0x3f3f3f3f;
    typedef long long LL;
    int a,b;
    int main(){
    	cin>>a>>b;
    	switch(a+b){
    		case 1:cout<<"one";break;
    		case 2:cout<<"two";break;
    		case 3:cout<<"three";break;
    		case 4:cout<<"four";break;
    		case 5:cout<<"five";break;
    		case 6:cout<<"six";break;
    		case 7:cout<<"seven";break;
    		case 8:cout<<"eight";break;
    		case 9:cout<<"nine";break;
    		default:cout<<"None";break;
    	}
    	return 0;
    }
    
    • @ 2025-5-6 22:38:49

      这本来是switch-case的裸题

信息

ID
875
时间
1000ms
内存
128MiB
难度
5
标签
递交数
212
已通过
86
上传者