aiheshan

有多自律,才能有多自由

导航

UVa 488 - Triangle Wave

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=429

题目:每个例子输入2个数,一个是wave的幅度,一个是重复的个数。

例如:
Input
1

3
2

output:
1
22
333
22
1

1
22
333
22
1

思路: 将1,22,333,···,999999999.字符串存在数组里。按照幅度打印输出就好。然后注意一下空行。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 
 5 char cc[9][10]={"1","22","333","4444","55555","666666","7777777","88888888","999999999"};
 6 
 7 int main()
 8 {
 9   // freopen("input.txt","r",stdin);
10   // freopen("output.txt","w",stdout);
11    int t,n,m,i,j,k;
12    cin>>t;
13    while(t--)
14    {
15       cin>>n>>m;
16       for(i=0;i<m;i++)
17       {
18        for(j=0;j<n;j++)
19           cout<<cc[j]<<'\n';
20        for(j=n-2;j>=0;j--)
21           cout<<cc[j]<<'\n';
22        if(i<m-1)
23         cout<<'\n';  
24       }
25        if(t>0)
26         cout<<'\n';
27 
28     }
29     return 0;
30 }     

 

posted on 2016-08-03 23:30  aiheshan  阅读(344)  评论(0编辑  收藏  举报