10 solutions

  • 1
    @ 2022-4-2 9:48:39

    两种方法 都供上了。递归 和 用栈。

    #include <iostream>
    #include <string>
    #include <stack>
    
    using namespace std;
    
    char charr[26] = { 'A','B','C','D','E','F','G','H','I','J'
    ,'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
    };
    
    void jinzhuan(int X,int M) {
    	if (X == 0) {
    		return;// 等于 0 进行返回
    	}
    	jinzhuan(X / M, M);
    	int temp = X % M;
    
    	if (temp < 10) {
    		cout << temp;
    	}
    	else {
    		cout << charr[temp - 10];
    	}
    	
    }
    
    
    
    int main(void) {
    	int X, M;
    	cin >> X >> M;
    	/*stack<int> s;
    
    	while (X != 0) {
    		s.push(X % M);
    		X /= M;
    	}
    	while (!s.empty()) {
    		int temp = s.top();
    		if (temp < 10) {
    			cout << temp;
    		}
    		else {
    			cout << charr[temp - 10];
    		} 
    		s.pop();
    	}*/
    	jinzhuan(X, M);
    
    	return 0;
    }
    

    Information

    ID
    288
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    4
    Tags
    # Submissions
    121
    Accepted
    55
    Uploaded By