The following program is my ACcepted code for UVA-441 .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃UVA 441 的AC code!
//This program is for UVA 441 Lotto
//題目來源 Problem link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=382
#include<stdio.h>
#include<string.h>
using namespace std;
int K, num[13], ans[13];
void DFS(int ansNum, int p, int K)
{
//printf("%d ", ans[ansNum]);
if(ansNum == 6)
{
for(int i = 0; i < 5; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[5]);
return;
}
if(p >= K)//now the position is in K index
return;
ans[ ansNum ] = num[p];
DFS(ansNum + 1, p + 1, K);
DFS(ansNum, p + 1, K);
}
int main()
{
bool start = true;
while(scanf("%d", &K) != EOF)
{
if(K == 0)
break;
if( !start)//blank line between cases
printf("\n");
else
start = false;
for(int i = 0; i < K; i++)
scanf("%d", &num[i] );
DFS(0, 0, K);
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃UVA 441 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
//This program is for UVA 441 Lotto
//題目來源 Problem link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=382
#include<stdio.h>
#include<string.h>
using namespace std;
int K, num[13], ans[13];
void DFS(int ansNum, int p, int K)
{
//printf("%d ", ans[ansNum]);
if(ansNum == 6)
{
for(int i = 0; i < 5; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[5]);
return;
}
if(p >= K)//now the position is in K index
return;
ans[ ansNum ] = num[p];
DFS(ansNum + 1, p + 1, K);
DFS(ansNum, p + 1, K);
}
int main()
{
bool start = true;
while(scanf("%d", &K) != EOF)
{
if(K == 0)
break;
if( !start)//blank line between cases
printf("\n");
else
start = false;
for(int i = 0; i < K; i++)
scanf("%d", &num[i] );
DFS(0, 0, K);
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!