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> # ...
随机推荐
- Java线程和多线程(八)——Thread Dump
Java的Thread Dump就是列出JVM中所有激活状态的线程. Java Thread Dump Java Thread Dump在分析应用性能瓶颈和死锁的时候,是非常有效的. 下面将介绍多种不 ...
- 转载: keepalived工作原理和配置说明
转自:http://outofmemory.cn/wiki/keepalived-configuration keepalived是什么 keepalived是集群管理中保证集群高可用的一个服务软件, ...
- leetcode 【 Linked List Swap Nodes in Pairs 】 python 实现
题目: Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- Git上手:使用Tortoisegit操作Git
在工作中,为了提高git使用效率,更多会采用git图形化工具来操作git.(特殊情况下才使用git命令行操作git) git自带的图形化工具界面不够友好,就选择第三方git图形化工具,市面上第三方gi ...
- spring 笔记2:Spring MVC : Did not find handler method for 问题的解决
日志显示为: Looking up handler method for path /***Did not find handler method for [/***]No mapping found ...
- Python 推导式推导序列
推导式是从一个或多个迭代器快速创建序列的方法.它可以将循环和条件判断结合,从而避免冗长的代码. 一.列表推导式 语法: [表达式 for item in 可迭代对象] [表达式 for item in ...
- Java基础-7数组
一).什么是数组: 数组是一组具有相同类型和名称的变量集合,把一系列相同类型的数据保存在一起,这些变量称为数组的元素:每个元素都有一个编号,这个编号叫做下标,下标从 0 开始:元素的个数被称为数组的长 ...
- Python全栈工程师(exercises)
# # 练习: # # 1. 用map函数求: # # 1**3 + 2**3 + 3 ** 3 + .... 9**3 的和 def add_(x): return x ** 3 print(sum ...
- Python全栈工程师(Linux基本操作)
ParisGabriel Python 入门基础 Linux :Ubuntu操作系统 首先我们说的是Linux操作系统常用的快捷键以及终端命令 一. VMware ...
- HDU 1171 Big Event in HDU 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory ...