UVa490 - Rotating Sentences-字符串-难度2
2013-12-23 11:35
435 查看
题目链接:
In ``Rotating Sentences,'' you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them
from top to bottom and right to left.
case English letters. (NOTE: Tabs are not legal characters.)
The output of the program should have the last sentence printed out vertically in the leftmost column; the first sentence of the input would subsequently end up at the rightmost column.
代码+思路
Rotating Sentences |
from top to bottom and right to left.
Input and Output
As input to your program, you will be given a maximum of 100 sentences, each not exceeding 100 characters long. Legal characters include: newline, space, any punctuation characters, digits, and lower case or uppercase English letters. (NOTE: Tabs are not legal characters.)
The output of the program should have the last sentence printed out vertically in the leftmost column; the first sentence of the input would subsequently end up at the rightmost column.
Sample Input
Rene Decartes once said, "I think, therefore I am."
Sample Output
"R Ie n te h iD ne kc ,a r tt he es r eo fn oc re e s Ia i ad m, . "
代码+思路
*2) 输入数据结束符号是回车'\n' *3) 要得到最大长度,不足最大长度的添‘ ’空格 */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAX = 101; char ans[MAX][MAX]; int main() { #ifdef LOCAL freopen("f:\\input.txt", "r", stdin); freopen("f:\\output.txt", "w", stdout); #endif memset(ans, 0, sizeof(ans)); char m; int i = 0, j = 0, maxRow = 0; while(scanf("%c", &m) != EOF) { if(m != '\n') { ans[j++][i] = m; if(maxRow < j) maxRow = j;//得到最大长度 } else { ++i; j = 0; } } for(int a = 0; a != maxRow; a++) { for(int b = i - 1; b >= 0; b--)//因为最后一个回车使i多了1个 { if(ans[a][b] != 0) cout << ans[a][b]; else cout << ' ';//不足最大长度的添空格 } cout << endl; } return 0; }
相关文章推荐
- 嵌入式linux通用截图工具
- JS中的异常处理方法分享
- Redis网站
- MatrixCursor 与 AbstractCursor实现Cursor 封装
- Spinlock在ARM及X86平台上的实现
- 判别四位平方数以及floor函数用法
- wpa_supplicant用法及分析
- 关于释放资源,有时候不能太相信 POP了,
- jquery 元素选择器集合
- Mysql InnoDB Plugin安装 install
- 14 cocos2d ScrollView
- left join on、where后面的条件的区别
- 《视频解密》中文版(第四版)第十章 H.261和H.263(第一部分)
- maven环境快速搭建
- cocos2dx常见动作
- 2.6.37的setup_arch
- JS中的异常处理方法分享
- 第三部分:Android 应用程序接口指南---第三节:应用程序资源---第一章 资源提供
- php 遍历文件夹
- python定时采集摄像头图像上传ftp服务器功能实现