UVA-10879 Code Refactoring

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章