The following program is my ACcepted code for UVA-488.
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃UAV 488的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
//This program is for UVa 488 Triangle Wave
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=429
/*
a very simple problem
one trick is the note:
NOTE: There is a blank line after each separate waveform, excluding the last one.
Therefore, we should set condition to control the blank line
*/
#include<stdio.h>
#include<iostream>
using namespace std;
/*
input integer Amplitude and Frequency
print the outcomes as problem described
*/
void wave(int amp, int fre)
{
for(int i=0; i<fre; i++)
{
for(int j=1 ; j<=amp; j++)
{
for(int k=1; k<=j; k++)
printf("%d",j);
printf("\n");
}
for(int j=amp-1 ; j>0; j--)
{
for(int k=1; k<=j; k++)
printf("%d",j);
printf("\n");
}
if(i != fre-1)
printf("\n");
}
}
int main()
{
int n, x, y;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d %d", &x, &y);
wave(x, y);
if(i != n-1)
printf("\n");
}
return 0;
}
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃UAV 488的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
//This program is for UVa 488 Triangle Wave
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=429
/*
a very simple problem
one trick is the note:
NOTE: There is a blank line after each separate waveform, excluding the last one.
Therefore, we should set condition to control the blank line
*/
#include<stdio.h>
#include<iostream>
using namespace std;
/*
input integer Amplitude and Frequency
print the outcomes as problem described
*/
void wave(int amp, int fre)
{
for(int i=0; i<fre; i++)
{
for(int j=1 ; j<=amp; j++)
{
for(int k=1; k<=j; k++)
printf("%d",j);
printf("\n");
}
for(int j=amp-1 ; j>0; j--)
{
for(int k=1; k<=j; k++)
printf("%d",j);
printf("\n");
}
if(i != fre-1)
printf("\n");
}
}
int main()
{
int n, x, y;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d %d", &x, &y);
wave(x, y);
if(i != n-1)
printf("\n");
}
return 0;
}
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!