标签:div each line space put OWIN double otto ons
There is an image with a height of H
pixels and a width of W pixels. Each of the pixels is represented by either .
or *
. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by Ci,j
.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H
pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C(i+1)/2,j
(the result of division is rounded down).
.
or *
.The input is given from Standard Input in the following format:
H W
C1,1...C1,W
:
CH,1...CH,W
Print the extended image.
很简单的一题,就是读入一些字符串再把每个分别输出2次。
(1)用char的数组实现(在输入时记得过滤掉回车)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define maxn 101 5 using namespace std; 6 char pic[maxn][maxn]; 7 int main() 8 { 9 int H, W; 10 scanf("%d%d", &H, &W); 11 getchar();//过滤掉回车 12 char temp; 13 for (int i = 1; i <= H; i++) 14 { 15 for (int j = 1; j <= W; j++) 16 { 17 scanf("%c", &pic[i][j]); 18 19 } 20 getchar();//过滤掉回车 21 } 22 //printf("%c", pic[1][1]); 23 for (int i = 1; i <= H; i++) 24 { 25 for (int j = 1; j <= W; j++) 26 { 27 printf("%c", pic[i][j]); 28 } 29 printf("\n"); 30 for (int j = 1; j <= W; j++) 31 { 32 printf("%c", pic[i][j]); 33 } 34 printf("\n"); 35 } 36 return 0; 37 }
(2)用string类实现
1 #include <cstring> 2 #include <iostream> 3 #include <cstdio> 4 #include <string> 5 using namespace std; 6 int main() 7 { 8 int H,W;cin>>H>>W; 9 for(int X=0;X<H;X++) 10 { 11 string S; 12 cin>>S; 13 cout<<S<<endl<<S<<endl; 14 } 15}
AtCoder Beginner Contest 049 B - Thin
标签:div each line space put OWIN double otto ons
原文地址:https://www.cnblogs.com/yangyi2120/p/14614579.html