“You know, it’s all very sweet, stealing from the
rich, selling to the poor...”
Jose Molina, "Firefly."
Your task is to graph the price of a stock over time. In one unit of time, the stock can either Rise, Fall or stay Constant. The stock’s price will be given to you as a string of R’s, F’s and C’s. You need to graph it using the characters ’/’ (slash), ’\’ (backslash) and ’_’ (underscore).
Input
The first line of input gives the number of cases, N. N test cases follow. Each one contains a string of at least 1 and at most 50 upper case characters (R, F or C).
Output
For each test case, output the line ‘Case #x:’, where x is the number of the test case. Then print the graph, as shown in the sample output, including the x- and y-axes. The x-axis should be one character longer than the graph, and there should be one space between the y-axis and the start of the graph. There should be no trailing spaces on any line. Do not print unnecessary lines. The x-axis should always appear directly below the graph. Finally, print an empty line after each test case.
Sample Input
1
RCRFCRFFCCRRC
Sample Output
Case #1:
| _
| _/\_/\ /
| / \__/
+---------------
题链接:UVA10800 Not That Kind of Graph
问题简述:
用3种字符绘图,R(绘制'/',光标右上移动),F(光标右下移动,绘制'\'),C(绘制'-',光标右移)。
问题分析:
虽然输入只有50字符,但是一直上移或下移都有可能,所以高度就需要2倍,还要考虑轴占一行。
列也需要增加若干列。
格式十分繁琐!需要注意!
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* UVA10800 Not That Kind of Graph */ #include <bits/stdc++.h> using namespace std; const int N = 50; char s[N]; char board[N + N + 2][N + 4]; int main() { int n, caseno = 0, len; scanf("%d", &n); while(n--) { scanf("%s", s); // 填充底板 memset(board, ' ', sizeof(board)); // 画图 int maxrow = N, minrow = N + 1, row = N; for(int i = 0; s[i]; i++) { if(s[i] == 'F') { board[++row][i + 2] = '\\'; maxrow = max(maxrow, row); } else if(s[i] == 'C') { board[row][i + 2] = '_'; minrow = min(minrow, row); } else if(s[i] == 'R') { minrow = min(minrow, row); board[row--][i + 2] = '/'; } len = i + 3; } // 画坐标轴 board[maxrow + 1][0] = '+'; for(int i = 1; i <= len; i++) board[maxrow + 1][i] = '-'; for(int i = minrow; i <= maxrow; i++) board[i][0] = '|'; // 去末尾空格 maxrow++; for(int i = minrow; i <= maxrow; i++) { int j = N + 3; while(board[i][j] == ' ') { board[i][j] = '\0'; j--; } } // 输出结果 printf("Case #%d:\n", ++caseno); for(int i = minrow; i <= maxrow; i++) puts(board[i]); putchar('\n'); } return 0; }