AK acmoj.Print a Frame

mac2024-03-09  24

题目描述

Print a Frame

Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm.

输入 The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

输出 For each dataset, print the frame made of ‘#’ and ‘.’.

Print a blank line after each dataset.

样例输入 3 4 5 6 3 3 0 0 样例输出 提示 3 ≤ H, W ≤ 300

#include<bits/stdc++.h> using namespace std; int main() { int a,b; while(cin>>a>>b) { if(a==0&&b==0) break; for(int i=1;i<=a;i++) { if(i==1||i==a) { for(int j=0;j<b;j++) { cout<<"#"; } cout<<endl; } else { for(int j=1;j<=b;j++) { if(j==1||j==b) cout<<"#"; else cout<<"."; } cout<<endl; } } cout<<endl; } return 0; }
最新回复(0)