<每日 1 OJ> -Table

上圖是一個Mysql查詢結果圖,咱們看到這個表格很是漂亮,只須要使用」+」和」-」兩個符號就能夠打印,如今你的任務是打印一個n×m的表格咱們定義單位長度(水平方向有三個」-」,豎直方向有一個」| 」,」|」對齊」+」)的矩形表格爲html

解答要求時間限制:1000ms, 內存限制:64MB
輸入

輸入只有一行包含兩個整數n和m(0<n,m<13)。算法

輸出

輸出n×m的表格。sql

樣例

輸入樣例 1 複製markdown

1 1

輸出樣例 1ui

+---+
|   |
+---+

輸入樣例 2 複製spa

1 2

輸出樣例 2code

+---+---+
|   |   |
+---+---+

 1 #include "stdafx.h"
 2 #include "stdlib.h"
 3 void PrintMysqlSolution(int rowNum, int colNum);
 4 
 5 int _tmain(int argc, _TCHAR* argv[])
 6 {
 7     int rowNum;
 8     int colNum;
 9     scanf_s("%d %d",&rowNum,&colNum);
10     PrintMysqlSolution(rowNum,colNum);
11     system("pause");
12     return 0;
13 }
14 //算法 ,一行一行的打印
15 void PrintMysqlSolution(int rowNum, int colNum)
16 {
17      //首先根據輸入的列數打印第一行的圖形
18      for(int colIndex=0;colIndex<colNum;colIndex++)
19      {
20          printf("+---");     
21      }
22     printf("+\n");
23     
24     //而後根據輸入的行列,打印剩餘部分的圖形
25     for(int rowIndex=0;rowIndex<rowNum;rowIndex++)
26     {
27         for(int colIndex=0;colIndex<colNum;colIndex++)
28         {
29             
30             printf("|   ");
31             
32         }
33         printf("|\n");
34       
35      //根據列數,打印最後一行的圖形,和第一行同樣
36      for(int colIndex=0;colIndex<colNum;colIndex++)
37      {
38          printf("+---");     
39      }
40       printf("+\n");
41         
42     }
43 
44 }
相關文章
相關標籤/搜索