码迷,mamicode.com
首页 > 其他好文 > 详细

uva 488 - Triangle Wave

时间:2016-01-01 01:53:35      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享
 1 /*
 2  * Author: Quickgrid ( Asif Ahmed )
 3  * Site: https://quickgrid.wordpress.com
 4  * Problem: UVA 488 ( Triangle Wave )
 5  */
 6 #include<stdio.h>
 7  
 8 /* For this problem amplitude does not exceed 9, so you can cheat <span class="wp-smiley wp-emoji wp-emoji-smile" title=":)">:)</span> */
 9 const char *a[] = {"", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"};
10  
11 int main(){
12     register unsigned n, i, j, k;
13     scanf("%u", &n);
14  
15     while(n--){
16         unsigned amp, times;
17         scanf("%u%u", &amp, &times);
18  
19         while(times--){
20             for(i = 1; i < amp; ++i)
21                 /* Just print the predefined strings */
22                 printf("%s\n", a[i]);
23  
24             for(k = i; k; --k)
25                 printf("%s\n", a[k]);
26  
27             if(times || n)
28                 printf("\n");
29         }
30     }
31     return 0;
32 }
c

 

技术分享
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 const string a[] = {"", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"};
 7 
 8 int main()
 9 {
10     register unsigned n, i, j, k;
11     string output, total = "";
12     scanf("%u", &n);
13 
14     while(n--)
15     {
16         unsigned amp, times;
17         scanf("%u%u", &amp, &times);
18         output = "";
19        
20         while(times--)
21         {
22             for(i=1; i<amp; ++i)
23                 output += a[i] + "\n";
24             for(k=i; k; --k)
25                 output += a[k] + "\n";
26             
27             if(times || n)
28                 output += "\n";
29         }
30         total += output;
31     }
32 
33     cout << total;
34     return 0;
35 }
c++

 

代码来源

 

uva 488 - Triangle Wave

标签:

原文地址:http://www.cnblogs.com/aze-003/p/5092864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!