zoukankan      html  css  js  c++  java
  • 蓝桥杯-基础练习-字母图形

    蓝桥杯-基础练习-字母图形

    动态分配空间实现,两个测试过不去,80分

    #include <iostream> 
    using namespace std;
    int main(){
        int n,m;
        cin >> n >> m;
        char **a = new char*[n];
        for(int i = 0; i < n; i++)
            a[i] = new char[m];
        for(int i = 0; i < n; i++){
            int k = 0;
            for(int j = i; j < m; j++){
                a[i][j] = 'A'+ k;
                k++;
            }
            k = 0;
            for(int j = i; j >=0;j--){
                a[i][j] = 'A'+k;
                k++;
            }
        }
        for(int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                cout << a[i][j];
            }
            cout << endl;
            delete []a[i];
        }
        delete []a;
        return 0;
    }
    

    数组固定分配内存,测试全过。

    #include <iostream> 
    using namespace std;
    int main(){
        int n,m;
        cin >> n >> m;
        char a[26][26] = {0};
        for(int i = 0; i < n; i++){
            int k = 0;
            for(int j = i; j < m; j++){
                a[i][j] = 'A'+ k;
                k++;
            }
            k = 0;
            for(int j = i; j >=0;j--){
                a[i][j] = 'A'+k;
                k++;
            }
        }
        for(int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                cout << a[i][j];
            }
            cout << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    poj 2312 Battle City
    poj 2002 Squares
    poj 3641 Pseudoprime numbers
    poj 3580 SuperMemo
    poj 3281 Dining
    poj 3259 Wormholes
    poj 3080 Blue Jeans
    poj 3070 Fibonacci
    poj 2887 Big String
    poj 2631 Roads in the North
  • 原文地址:https://www.cnblogs.com/chmod/p/15489938.html
Copyright © 2011-2022 走看看