Problem D: 字符构成的图形

xiaoxiao2021-02-27  391

HomeWeb BoardProblemSetStandingStatusStatistics

Problem D: 字符构成的图形

Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 1342   Solved: 832 [ Submit][ Status][ Web Board]

Description

定义CharGraph类,用于输出一个由指定字符组成的图形。该类包括:

1. 一个int类型数据成员,表示该图形的层数。

2. 一个char类型的数据成员,表示组成该图的字符。

3. void print()方法,用于根据指定格式输出字符图形。

Input

第1行N>0,表示有N个测试用例。

每个测试用例的输入由一个非负整数和一个字符组成。

Output

每个测试用例产生一组输出。

当指定的层数为0时,输出一个空行。

当指定的层数为正数时,输出每层字符个数自上到下依次递增且靠左对齐的直角三角形。

当指定的层数为负数时,输出每层字符个数自上而下依次递减其靠左对齐的直角三角形。

具体格式见样例。

Sample Input

310 c0 0-5 +

Sample Output

ccccccccccccccccccccccccccccccccccccccccccccccccccccccc+++++++++++++++

HINT

Append Code

append.cc, [ Submit][ Status][ Web Board]

한국어<  中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin

#include<iostream> #include<string> using namespace std; class CharGraph{ char ch; int n; public : CharGraph(int a,char c):n(a),ch(c){} void print() { if(n==0) cout << endl; if(n>0) for(int i = 0 ; i < n ; i++) for(int j = 0 ; j <= i ; j++) { cout << ch; if (j==i) cout << endl; } if (n < 0 ) { n = -n; for (int i = 0; i < n ; i++) for (int j = 0 ; j < n-i; j++) { cout << ch; if (j == n-i-1) cout << endl; } } } }; int main() { int cases, n; char c; cin>>cases; for (int i = 0; i < cases; i++) { cin>>n>>c; CharGraph cGraph(n, c); cGraph.print(); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2886.html

最新回复(0)