刷題證明
A | CodeForces 1057A | Bmail Computer Network |
#include<bits/stdc++.h>
using namespace std;
int record[200005] = {}, ans[200005] = {};
int main()
{
int end; int count = 0;
cin >> end;
for (int i = 2; i <= end; i++)
{
cin >> record[i];
}
int temp = end;
while (temp != 1)
{
ans[++count] = temp;
temp = record[temp];
}
ans[++count] = 1;
for (int i = count;i >= 1; i--)
{
printf("%d ", ans[i]);
}
return 0;
}
B | UVA 441 | Lotto |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int flag=0;
int n=0,a,b,c,d,e,f;
int ans[100];
while(cin>>n)
{
if(flag!=0&&n!=0)
{
cout<<endl;
}
if(n==0)break;
for(int i=0;i<n;i++)cin>>ans[i];
for(a=0;a<n-5;a++)
{
for(b=a+1;b<n-4;b++)
{
for(c=b+1;c<n-3;c++)
{
for(d=c+1;d<n-2;d++)
{
for(e=d+1;e<n-1;e++)
{
for(f=e+1;f<n;f++)
{
cout<<ans[a]<<" "<<ans[b]<<" "<<ans[c]<<" "<<ans[d]<<" "<<ans[e]<<" "<<ans[f]<<endl;
}
}
}
}
}
}
flag++;
}
return 0;
}