30分求助
查看原帖
30分求助
725322
a_san_de_dou_li楼主2023/8/19 14:29
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			for(int a=1;j<=3;j++)
			{
				for(int b=1;j<=3;j++)
				{
					for(int c=1;j<=3;j++)
					{
						for(int d=1;j<=3;j++)
						{
							for(int e=1;j<=3;j++)
							{
								for(int f=1;j<=3;j++)
								{
									for(int k=1;j<=3;j++)
									{
										for(int l=1;j<=3;j++)
										{
											if(i+j+a+b+c+d+e+f+k+l==n)
											{
												ans++;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	if(ans==0)
	{
		return 0;
	}
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			for(int a=1;j<=3;j++)
			{
				for(int b=1;j<=3;j++)
				{
					for(int c=1;j<=3;j++)
					{
						for(int d=1;j<=3;j++)
						{
							for(int e=1;j<=3;j++)
							{
								for(int f=1;j<=3;j++)
								{
									for(int k=1;j<=3;j++)
									{
										for(int l=1;j<=3;j++)
										{
											if(i+j+a+b+c+d+e+f+k+l==n)
											{
												cout<<i<<" ";
												cout<<j<<" ";
												cout<<a<<" ";
												cout<<b<<" ";
												cout<<c<<" ";
												cout<<d<<" ";
												cout<<e<<" ";
												cout<<f<<" ";
												cout<<k<<" ";
												cout<<l<<" ";
												cout<<endl;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return 0;
}
2023/8/19 14:29
加载中...