#22036: 請問為什麼會出現溢位狀態,我已經過了,可是還是很好奇為甚麼原本寫法會錯誤


twm0970420996@gmail.com (小胖胖胖)

學校 : 不指定學校
編號 : 94884
來源 : [122.116.200.57]
最後登入時間 :
2020-07-13 23:16:38
e566. 10190 - Divide, But Not Quite Conquer! -- UVA | From: [114.137.22.207] | 發表日期 : 2020-08-11 11:00

#include <iostream>
using namespace std;

int main()
{
    int n = 0 , m = 0;
    while(cin >> n >> m){
        int counter = 1;
        int r[20000] = {0};
        r[0] = n;
    for(int i = 1 ; i < 20000 ; i++){
        r[i] =  n / m;
        n /= m;
        if(n == 1){
            r[i+1] = 1;
            counter = i+1;
            break;
        }
    }
        char t = 'f';
        for(int i = 0 ; i < counter - 1  ; i++){
            if(r[i] % m != 0){
                t = 't';
            }
        }
        if(t == 't'){
            cout << "Boring!" << endl;
        }else{
            for(int i = 0 ; i < counter ; i++){
                cout << r[i] << " ";
            }
            cout << endl;
        }

    }



}
 
ZeroJudge Forum