1 solutions

  • 0
    @ 2025-11-5 19:08:56

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n,a,b;
    	cin>>n;
    	for (int k=1; k<=n; k++)
    	{
    		cin>>a>>b;
    		if (a==1)	//a==1
    			for (int i=1; i<=b; i++) cout<<"X"<<endl;
    		else
    		{
    			cout<<"X";
    			for (int i=2; i<=a-1; i++) cout<<" ";
    			cout<<"X"<<endl;	//X的第一行
    			for (int t=1; t<=b; t++)	//重复b次
    			{
    				for (int i=2; i<=a/2; i++)	//上半部分
    				{
    					for (int j=1; j<=a; j++)
    						if (i==j || i+j==a+1) cout<<"X";
    						else if (i+j<=a) cout<<" ";
    					cout<<endl;
    				}
    				for (int i=a/2+1; i<=a; i++)//下半部分
    				{
    					for (int j=1; j<=a; j++)//输出前面
    						if (i==j || i+j==a+1) cout<<"X";
    						else if (i>j) cout<<" ";
    					cout<<endl;
    				}
    			}
    		}
    		if (k<n) cout<<endl;
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    19198
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By