2016-08-12
UVA - 10879 Code Refactoring
題目大意:找出一個數的任意兩對因子。不一定要與樣例相同。
解題思路:枚舉能整除的輸出兩對,注意格式。
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n, num;
scanf("%d",&n);
for (int i = 1; i <= n; i++) {
int temp = 0;
scanf("%d",&num);
cout << "Case #" << i << ": " << num;
for (int j = 2; j < num; j++) {
if ( num % j == 0 ) {
cout << " = " << j << " * " << num/j;
if ( ++temp == 2 )
break;
}
}
cout << endl;
}
return 0;
}