Last active
November 5, 2019 08:53
-
-
Save pinglunliao/90f2a9bb2d859f0e3900 to your computer and use it in GitHub Desktop.
c013: 00488 - Triangle Wave. FYI: https://yunlinsong.blogspot.com/2015/03/c013-00488-triangle-wave.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void prtTriangle(short a, int f) | |
{ | |
short start = -a + 1; | |
short end = a - 1; | |
for( int times = 0; times < f - 1; times++ ) | |
{ | |
for(short n = start; n <= end; n++) | |
{ | |
int out = a - abs(n); | |
for(int k = abs(n); k < a; k++) | |
cout << out; | |
cout << endl; | |
} | |
cout << endl; | |
} | |
for(short n = start; n <= end; n++) | |
{ | |
int out = a - abs(n); | |
for(int k = abs(n); k < a; k++) | |
cout << out; | |
cout << endl; | |
} | |
} | |
int main() | |
{ | |
int n, a, f; | |
cin >> n; | |
while( cin >> a >> f ) | |
{ | |
prtTriangle(a, f); | |
n--; | |
if( n <= 0 ) | |
break; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment