include
using namespace std;
struct Node{
int x,y,z;
}stu[1000001];
bool cmp(Node a,Node b)
{
return a.x*10000+a.y*100+a.z<b.x*10000+b.y*100+b.z;
}
int main()
{
int t,i;cin>>t;
for(i=0;i<t;i++){
int k,n;cin>>n>>k;
int j,index=0;
if(k-n<0||2*n-k<0){
cout<<"case #"<<i<<":\n";
cout<<-1<<endl;
continue;
}
for(j=k-2*n;j<=(k-n)/2;j++){
if(j>=0&&k-n-2*j>=0&&2*n-k+j>=0){
stu[index].x=j;
stu[index].y=k-n-2*j;
stu[index++].z=2*n-k+j;
}
}
sort(stu,stu+index,cmp);
cout<<"case #"<<i<<":\n";
for(j=0;j<index;j++){
cout<<stu[j].x<<" "<<stu[j].y<<" "<<stu[j].z<<endl;
}
}
}
屎山代码
大一写的代码..现在看确实很冗长..