#29227: C++自己在終端機上測試是對的但是用測資測時卻是錯誤的,想請教各位高手,自己輸入20和17測都和解答一樣


evan881101 (Evan Chen)


#include <iostream>
using namespace std;

int main(){
int k;
int b;
int begin;
cin >> b;
int count_factor;
k = 2;
begin = 1;
if(b <= 100000000 && b >1 ){
while(k <= b){
while(b%k == 0){
count_factor++;
b = b/k;
 
}
if(begin == 1){
if(count_factor == 1){
cout << k;
count_factor = 0;
begin = 0;
}
if(count_factor > 1){
cout << k << "^" << count_factor;
count_factor = 0;
begin = 0;
}
}
else if(begin == 0){
if(count_factor == 1){
cout << " * " << k;
count_factor = 0;
}
if(count_factor > 1){
cout << " * " << k << " ^ " <<count_factor;
count_factor = 0;
}
}
k++;
}
cout << endl;
return 0;
}
else {
return 0;
}
 

}


#29228: Re:C++自己在終端機上測試是對的但是用測資測時卻是錯誤的,想請教各位高手,自己輸入20和17測都和解答一樣


cges30901 (cges30901)



int count_factor;

cout << " * " << k << " ^ " <<count_factor;


1. count_factor沒有初始化

2. ^前後沒有空格

#29241: Re:C++自己在終端機上測試是對的但是用測資測時卻是錯誤的,想請教各位高手,自己輸入20和17測都和解答一樣


evan881101 (Evan Chen)



int count_factor;

cout << " * " << k << " ^ " <<count_factor;


1. count_factor沒有初始化

2. ^前後沒有空格

好的非常謝謝您!!!