1 条题解

  • 0
    @ 2023-6-11 12:21:13

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int h,m;
    int main( ){
    	string s[30] = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","thirty","forty","fifty"};
        cin>>h>>m;
        if(m == 0){
        	if(h <= 20){
        		cout<<s[h]<<" "<<"o'clock";
    		}else{
    			cout<<s[20]<<" "<<s[h % 10]<<" "<<"o'clock";
    		}
    	}else{
    		if(h <= 20){
        		cout<<s[h]<<" ";
    		}else{
    			cout<<s[20]<<" "<<s[h % 10]<<" ";
    		}
    		if(m <= 20){
    			cout<<s[m];
    		}else{
    			if(m > 20&&m < 30){
    				cout<<s[20]<<" "<<s[m % 10];
    			}else if(m >= 30&&m < 40){
    				cout<<s[21]<<" "<<s[m % 10];
    			}else if(m >= 40&&m < 50){
    				cout<<s[22]<<" "<<s[m % 10];
    			}else{
    				cout<<s[23]<<" "<<s[m % 10];
    			}
    		}
    	}
    	
        return 0;
    }
    
    
    
    

    Java :

    import java.util.Scanner;
    public class Main {
        static int m;
        static int h;
        static String eng[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","thirty","forty","fifty"};
        static String r=" o'clock";
        
        static void num_to_eng(int num){
            int a,b;
            a=num/10;
            b=num%10;
            if(num<=20)
                System.out.print(eng[num]);
            else
            {
                System.out.print(eng[a+18]);
                if(b!=0)
                    System.out.print(" "+eng[b]);
            }
        }
        
        static void output(){
            if(m==0){
                num_to_eng(h);
                System.out.println(r);
                
            }
            else{
                num_to_eng(h);
                System.out.print(" ");
                num_to_eng(m);
                System.out.println();
            }
            
        }
        public static void main(String [] args){
            Scanner sc=new Scanner(System.in);
            h=sc.nextInt();
            m=sc.nextInt();
            output();
            
        }
    
    }
    
    • 1

    信息

    ID
    2717
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者