Why LeetCode doesn't accept my code?


  • 0
    B

    There is the result of the judge.


    Integer to English Words

    Submission Details
    1 / 601 test cases passed.
    Status: Wrong Answer
    Submitted: 23 minutes ago
    Input:
    123
    Output:
    "One Hundred Twenty Three"
    Expected:
    "One Hundred Twenty Three"


    My code:

     class Solution {
    private:
    	int one,thousand, million, billion;
    	string NumToString(int num){
    		if (num == 0)
    			return "\0";
    		int s0, s1, s2;
    		string tmp;
    		s0 = num % 10;
    		s1 = num % 100;
    		s2 = (num / 100) % 10;
    		if (s1 < 21){
    			switch (s1){
    			case 0: break;
    			case 1: tmp += "One " ; break;
    			case 2: tmp += "Two " ; break;
    			case 3: tmp += "Three " ; break;
    			case 4: tmp += "Four " ; break;
    			case 5: tmp += "Five " ; break;
    			case 6: tmp += "Six " ; break;
    			case 7: tmp += "Seven " ; break;
    			case 8: tmp += "Eight " ; break;
    			case 9: tmp += "Nine " ; break;
    			case 10: tmp += "Ten " ; break;
    			case 11: tmp += "Eleven " ; break;
    			case 12: tmp += "Twelve " ; break;
    			case 13: tmp += "Thirteen " ; break;
    			case 14: tmp += "Fourteen " ; break;
    			case 15: tmp += "Fifteen " ; break;
    			case 16: tmp += "Sixteen " ; break;
    			case 17: tmp += "Seventeen " ; break;
    			case 18: tmp += "Eighteen " ; break;
    			case 19: tmp += "Nineteen " ; break;
    			case 20: tmp += "Twenty " ; break;
    			};
    		}
    		else{
    			switch (s0){
    			case 0: break;
    			case 1: tmp += "One " ; break;
    			case 2: tmp += "Two "; break;
    			case 3: tmp += "Three "; break;
    			case 4: tmp += "Four "; break;
    			case 5: tmp += "Five "; break;
    			case 6: tmp += "Six "; break;
    			case 7: tmp += "Seven "; break;
    			case 8: tmp += "Eight "; break;
    			case 9: tmp += "Nine "; break;
    			}
    			switch (s1 / 10){
    			case 2: tmp = "Twenty " + tmp; break;
    			case 3: tmp = "Thirty " + tmp; break;
    			case 4: tmp = "Fourty " + tmp; break;
    			case 5: tmp = "Fifty " + tmp; break;
    			case 6: tmp = "Sixty " + tmp; break;
    			case 7: tmp = "Seventy " + tmp; break;
    			case 8: tmp = "Eighty " + tmp; break;
    			case 9: tmp = "Ninety " + tmp; break;
    			}
    		}
    		switch (s2){
    		case 0: break;
    		case 1: tmp = "One Hundred " + tmp; break;
    		case 2: tmp = "Two Hundred " + tmp; break;
    		case 3: tmp = "Three Hundred " + tmp; break;
    		case 4: tmp = "Four Hundred " + tmp; break;
    		case 5: tmp = "Five Hundred " + tmp; break;
    		case 6: tmp = "Six Hundred " + tmp; break;
    		case 7: tmp = "Seven Hundred " + tmp; break;
    		case 8: tmp = "Eight Hundred " + tmp; break;
    		case 9: tmp = "Nine Hundred " + tmp; break;
    		}
    		cout << tmp << endl;
    		return tmp;
    	}
    public:
    	string numberToWords(int num){
    		if (num == 0)
    			return "Zero";
    		one = num % 1000;
    		thousand = (num / 1000) % 1000;
    		million = (num / 1000000) % 1000;
    		billion = (num / 1000000000) % 1000;
    		string temp = NumToString(billion) + (billion == 0 ? "" : "Billion ") + NumToString(million) + (million == 0 ? "" : "Million ") + NumToString(thousand) + (thousand == 0 ? "" : "Thousand ") + NumToString(one);
    		int i;
    		for (i = 0; temp[i] != '\0'; i++);
    		temp[i - 1] = temp[i];
    		return temp;
    	}
    	void tmp_sol_print(){
    		cout << "b:" << billion << endl
    			<< "m:" << million << endl
    			<< "t:" << thousand << endl
    			<< "o:" << one << endl;
    	}
    	
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.