5 条题解

  • 1
    @ 2024-2-6 9:06:46

    要是不写函数就太麻烦、太乱了,还是用函数好一点~

    已AC,请放心食用

    #include <iostream>
    using namespace std;
    void squ(int n)
    {
        for (int i = 1; i <= n; i++)
        {
            cout << "*";
        }
        cout << endl;
    }
    void are(int n)
    {
        for (int i = 1; i <= n - 2; i++)
        {
            cout << "*";
            for (int j = 1; j <= n - 2; j++)
            {
                cout << " ";
            }
            cout << "*" << endl;
        }
    }
    int main()
    {
        int n;
        cin >> n;
        squ(n);
        are(n);
        squ(n);
        return 0;
    }
    

    养成好习惯,看后点个赞😎!

    • 1
      @ 2023-12-19 11:17:21

      AC Code

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n;
          cin >> n;
          for (int i = 1; i <= n; i++)
              cout << "*";
          cout << endl;
          for (int i = 1; i <= n - 2; i++)
          {
              for (int j = 1; j <= n; j++)
              {
                  if (j == 1 || j == n)
                      cout << "*";
                  else
                      cout << " ";
              }
              cout << endl;
          }
          for (int i = 1; i <= n; i++)
              cout << "*";
          return 0;
      }
      
      • 1
        @ 2022-8-6 13:05:01
        #include <bits/stdc++.h>
        using namespace std;
        int n;
        int main()
        {
            cin >> n;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    if (i == 1 || i == n)
                    {
                        cout << "*";
                    }
                    else
                    {
                        if (j == 1 || j == n)
                        {
                            cout << "*";
                        }
                        else
                        {
                            cout << " ";
                        }
                    }
                }
                cout << endl;
            }
            return 0;
        }
        
        • 0
          @ 2023-7-31 18:19:11

          #include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 1;i <= n;i++) { for (int j = 1;j <= n;j++) { if (i != 1 and i != n) { if (j != 1 and j != n) { cout << " "; } else { cout << ""; } } else { cout << ""; } } cout << endl; } return 0; } //只有50分啊

          • 0
            @ 2023-7-8 19:14:23
            #include <iostream>
            using namespace std;
            int main(){
                int k,net=1,x=0,sum=0;
                cin>>k;
                for(int i=1;i<=k;i++){
                    sum+=net,x++;
                    if(x==net)net++,x=0;
                }
                cout<<sum<<endl;
                return 0;
            }
            
            • 1

            信息

            ID
            489
            时间
            1000ms
            内存
            128MiB
            难度
            1
            标签
            递交数
            118
            已通过
            81
            上传者