UVA 1593: Alignment of Code(模拟 Grade D)
题意:
格式化代码。每个单词对齐,至少隔开一个空格。
思路:
模拟。求出每个单词最大长度,然后按行输出。
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring> char words[][][];
int maxLen[]; char tmp[]; typedef char * pchar; int readStr(pchar &str, char *out) {
int num = ;
int ret = sscanf(str, "%s%n", out, &num);
//printf("str = %s\n", str);
str += num;
return ret;
} void myprint(char *str, int len) {
int i = ;
for (i = ; str[i]; i++) {
putchar(str[i]);
}
for (; i < len; i++) {
putchar(' ');
}
} int main() {
char *p;
int nowLine = ;
while (gets(tmp)) {
p = tmp;
int i = ;
while (readStr(p, words[nowLine][i]) != -) {
i++;
}
nowLine++;
} for (int i = ; i < nowLine; i++) {
for (int j = ; j < ; j++) {
if (strlen(words[i][j]) > maxLen[j]) {
maxLen[j] = strlen(words[i][j]);
}
}
} for (int i = ; i < nowLine; i++) {
for (int j = ; j < ; j++) {
if (strlen(words[i][j]) != ) {
if (j != ) printf(" ");
if (strlen(words[i][j+])) myprint(words[i][j], maxLen[j]);
else printf("%s", words[i][j]);
} else break;
}
printf("\n");
} return ;
}
UVA 1593: Alignment of Code(模拟 Grade D)的更多相关文章
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- Uva - 1593 - Alignment of Code
直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐. AC代码: #include <iostream> #inc ...
- UVA 1594:Ducci Sequence (模拟 Grade E)
题意: 对于一个n元组(a0,a1,...),一次变换后变成(|a0-a1|,|a1-a2|,...) 问1000次变换以内是否存在循环. 思路: 模拟,map判重 代码: #include < ...
- [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...
- 【习题5-1 UVA - 1593】Alignment of Code
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好. 这个作为场宽. 模拟输出就好. [代码] #include <b ...
- Alignment of Code UVA - 1593
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which ...
- UVa 1593 (水题 STL) Alignment of Code
话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]); 这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...
- uva 177:Paper Folding(模拟 Grade D)
题目链接 题意:一张纸,每次从右往左对折.折好以后打开,让每个折痕都自然的呈90度.输出形状. 思路:模拟折……每次折想象成把一张纸分成了正面在下的一张和反面在上的一张.维护左边和方向,然后输出.细节 ...
- UVA 1589:Xiangqi (模拟 Grade D)
题目: 象棋,黑棋只有将,红棋有帅车马炮.问是否死将. 思路: 对方将四个方向走一步,看看会不会被吃. 代码: 很难看……WA了很多发,还越界等等. #include <cstdio> # ...
随机推荐
- pocscan扫描框架的搭建
0x00 无意中看到了一篇文章 讲pocscan的搭建..就比较心动 决定自己也搭建一个这样的扫描平台 0x01 安装docker 用的是ubuntu yklin 16.04 x64的系统 在更新源之 ...
- python os模块练习题
# 1.获取某个文件所在目录的上一级目录. # 例如'D:\python\projects\test19.py'目录的结果 :D:\python\projects # 方法1 # path = os. ...
- 9 与python2交互
1.创建外键 # 创建room表 mysql> create table rooms(id )); Query OK, rows affected (0.01 sec) #创建学生表 mysql ...
- USACO Section2.3 Zero Sum 解题报告 【icedream61】
zerosum解题报告----------------------------------------------------------------------------------------- ...
- echarts 柱状图下钻功能
var drillDown = { getOption : function () { var option = null; option = { title: { text: ' ...
- 斐波那契数列的三种C++实现及时间复杂度分析
本文介绍了斐波那契数列的三种C++实现并详细地分析了时间复杂度. 斐波那契数列定义:F(1)=1, F(2)=1, F(n)=F(n-1) + F(n-2) (n>2) 如何计算斐波那契数 F( ...
- hadoop-eclipse环境搭建(二)
Eclipse插件配置 第一步:把我们的"hadoop-eclipse-plugin-1.0.0.jar"放到Eclipse的目录的"plugins"中,然后重 ...
- 五、SPR 单一职责
1.一个类具有什么职责,应该是站在他人的角度或者说是使用者的角度来定义.职责不是一件事,而是许多和职责相关的事组成的. 例如:一个快递员,除了送快递,还需要做分包.收款.那么快递员的职责是和快递相关的 ...
- Python中的多线程编程,线程安全与锁(一)
1. 多线程编程与线程安全相关重要概念 在我的上篇博文 聊聊Python中的GIL 中,我们熟悉了几个特别重要的概念:GIL,线程,进程, 线程安全,原子操作. 以下是简单回顾,详细介绍请直接看聊聊P ...
- [codevs1746][NOI2002]贪吃的九头龙
[codevs1746][NOI2002]贪吃的九头龙 试题描述 传说中的九头龙是一种特别贪吃的动物.虽然名字叫"九头龙",但这只是说它出生的时候有九个头,而在成长的过程中,它有时 ...