zzuli oj 1224: 画表格

/*
把每一行头部最为一个标记存入字符串head
根据标记不同,后面跟字符串:"--+" "  |"
循环次数由n m控制
*/

#include <bits/stdc++.h>
using namespace std;
const string x="--+";
const string y="  |";
string init(int n)
{
    string head = "+";
    for(int i=0;i<n;i++){
        head = head+"||+";
    }
    return head;
}

int main()
{
    int T;
    cin>>T;

    while(T--){
        int n,m;
        cin>>n>>m;
        
        string head = init(n);

        for(int i = 0;i<head.size();i++){
            if(head[i] == '+'){
                cout<<"+";
                for(int k = 0;k<m;k++)
                    cout<<x;
                cout<<endl;
            }
            else{
                cout<<"|";
                for(int k=0;k<m;k++)
                    cout<<y;
                cout<<endl;
            }
        }

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/f_zmmfs/article/details/81277086