5 条题解

  • 3
    @ 2022-11-23 19:47:43

    过分简单……

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

    AC过的~

    • 2
      @ 2023-7-29 21:33:27

      找规律输出即可

      参考代码(已AC):

      #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-i;j++)//输出空格
                  cout<<" ";
              for(int j=1;j<=i*2-1;j++)//输出*
                  cout<<"*";
              cout<<endl;//换行
          }
          return 0;
      }
      

      要是实在找不到规律的话,可以添加一个变量

      #include <bits/stdc++.h>
      using namespace std;
      int n,x=1;//x初始化为1
      int main()
      {
          cin>>n;
          for(int i=1;i<=n;i++)
          {
              for(int j=1;j<=n-i;j++)//输出空格
                  cout<<" ";
              for(int j=1;j<=x;j++)//输出*
                  cout<<"*";
              x+=2;//每一行输出结束,x增加2
              cout<<endl;//换行
          }
          return 0;
      }
      
      • 0
        @ 2023-7-7 13:25:13

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

        • 0
          @ 2022-8-6 13:38:42
          #include <iostream>
          using namespace std;
          int main()
          {
              int n; 
              cin >> n;
              for (int i = 1; i <= n; i++)
              {
                  for (int j = 1; j <= n - i; j++)
                  {
                      cout << " ";
                  }
                  for (int j = 1; j <= i * 2 - 1; j++)
                  {
                      cout << "*";
                  }
                  cout << endl;
              }
              return 0;
          }
          
          • 0
            @ 2021-9-5 14:59:00

            #include <iostream> using namespace std; int n ; int main() { cin >> n ; for ( int i = 1 ; i <= n ; i++ ) { for ( int j = 1 ; j <= n - i ; j++ ) cout << " " ; for ( int j = 1 ; j <= ( ( i - 1 ) * 2 ) + 1 ; j++ ) cout << "*" ;//找出规律就可以了~ cout << endl ; } return 0 ; }

            • 1

            【入门】字符图形4-星号正三角

            信息

            ID
            69
            时间
            1000ms
            内存
            16MiB
            难度
            3
            标签
            递交数
            243
            已通过
            138
            上传者