5 条题解

  • 3
    @ 2022-12-11 14:50:37
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,i,j,a[110][110];
        cin>>n;
        for(i=1;i<=n;i++)
        {
        	for(j=1;j<=n;j++)
            {
        		a[i][j]=((i-1)*n)+j;
    		}
    	}
    	for(i=1;i<=n;i++)
        {
    		for(j=1;j<=n;j++)
            {
    			cout<<setw(3)<<a[i][j];
    		}
    		cout<<endl;
    	}
        return 0;
    }//已AC
    
    • 1
      @ 2024-4-15 13:46:41

      不用二维数组轻松搞定

      #include <iostream>
      using namespace std;
      int main()
      {
          int n;
          cin >> n;
          for (int i=1;i<=n*n;i++)
          {
              if (i<10)
              {
                  cout << "  " << i;
              }
              else
              {
                  cout << " " << i;
              }
              if (i%n==0)
              {
                  cout << endl;
              }
          }
          return 0;
      }
      
      • 1
        @ 2024-2-18 12:21:49

        哪有这么简单的题啊,真不像话

        #include <iostream>
        using namespace std;
        int main()
        {
            int n;
            cin >> n;
            for (int i = 1; i <= n * n; i++)
            {
                if (i < 10)
                {
                    cout << "  ";
                }
                else
                {
                    cout << " ";
                }
                cout << i;
                if (i % n == 0)
                {
                    cout << endl;
                }
            }
            return 0;
        }
        
        • 1
          @ 2023-4-9 15:11:38
          #include <iostream>
          using namespace std;
          int main()
          {
              int n, x = 0;
              cin >> n;
              int a[n][n];
              for (int i = 1; i <= n; i++)
              {
                  for (int j = 1; j <= n; j++)
                  {
                      x++;
                      a[i][j] = x;
                      if (x / 10 == 0)
                      {
                          cout << "  " << a[i][j];
                      }
                      else
                      {
                          cout << " " << a[i][j];
                      }
                  }
                  cout << endl;
              }
              return 0;
          }
          
          • 0
            @ 2023-4-13 19:18:52

            谁说一定要用二维数组的。

            #include <iostream>
            using namespace std;
            int main()
            {
                int n;
                cin >> n;
                for(int i=1;i<=n;i++)
                {
                    cout << " ";
                    for(int j=1;j<=n;j++)
                    {
                        if((i-1)*n+j<10)
                        {
                            cout << " ";
                        }
                        cout << (i-1)*n+j << " ";
                    }
                    cout << endl;
                }
            }
            
            • 1

            信息

            ID
            184
            时间
            1000ms
            内存
            16MiB
            难度
            5
            标签
            递交数
            264
            已通过
            98
            上传者