题意:

格式化代码。每个单词对齐,至少隔开一个空格。

思路:

模拟。求出每个单词最大长度,然后按行输出。

代码:

#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)的更多相关文章

  1. UVA 1593 Alignment of Code(紫书习题5-1 字符串流)

    You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...

  2. Uva - 1593 - Alignment of Code

    直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐. AC代码: #include <iostream> #inc ...

  3. UVA 1594:Ducci Sequence (模拟 Grade E)

    题意: 对于一个n元组(a0,a1,...),一次变换后变成(|a0-a1|,|a1-a2|,...) 问1000次变换以内是否存在循环. 思路: 模拟,map判重 代码: #include < ...

  4. [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...

  5. 【习题5-1 UVA - 1593】Alignment of Code

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好. 这个作为场宽. 模拟输出就好. [代码] #include <b ...

  6. Alignment of Code UVA - 1593

      You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which ...

  7. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  8. uva 177:Paper Folding(模拟 Grade D)

    题目链接 题意:一张纸,每次从右往左对折.折好以后打开,让每个折痕都自然的呈90度.输出形状. 思路:模拟折……每次折想象成把一张纸分成了正面在下的一张和反面在上的一张.维护左边和方向,然后输出.细节 ...

  9. UVA 1589:Xiangqi (模拟 Grade D)

    题目: 象棋,黑棋只有将,红棋有帅车马炮.问是否死将. 思路: 对方将四个方向走一步,看看会不会被吃. 代码: 很难看……WA了很多发,还越界等等. #include <cstdio> # ...

随机推荐

  1. Mysql 表转换成 Sqlite表

    目前的转换仅仅支持对没有外键的Mysql数据表 准备: 下载安装 Sqlite Expert 软件 一 获取Mysql中的.sql文件,获取过程省略可以直接导出sql文件 二 在Sqlite Expe ...

  2. Result Maps collection does not contain value for xxxx

    这是mybatis查询返回值的错误,我在做一个查询数值的方法,但是我是这样写的: <select id="findSize" resultMap="long&quo ...

  3. videomon 环境搭建

    1.安装ACE-5.8.0.tar.bz2 tar -zxvf ACE-.tar.bz2 cd ACE_wrappers/mkdir buildcd build../configuremake &am ...

  4. Unicode字符图标

    http://unicode-table.com/cn/#control-character

  5. 《Cracking the Coding Interview》——第17章:普通题——题目8

    2014-04-28 23:35 题目:最大子数组和问题. 解法:O(n)解法. 代码: // 17.8 Find the consecutive subarray with maximum sum ...

  6. Pascal数据结构与算法

    第一章 数据结构与算法的引入 1.1 数据结构的基本概念 一. 学习数据结构的意义 程序设计 = 数据结构 + 算法 目前,80%的待处理的数据具有“算法简单”(四则运算.检索.排序等),“对象复杂” ...

  7. 【Spiral Matrix】cpp

    题目: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spira ...

  8. JMeter学习笔记(五) 文件上传接口测试

    此次测试的是上传图片接口,我把测试情况整理了一下,其他的上传文件接口都类似. 1.我通过jmeter的录制功能获取到了接口地址以及相关参数,如果有接口文档就会方便很多,此步骤就不多做说明了 2.因为上 ...

  9. docker部署思路

    1.docker安装2.拉取centos镜像或者Ubuntu镜像 看你用哪个3.使用镜像,run出来一个容器A4.进入容器A,安装uwsgi,把Django部署在下面5.在启动脚本中配置开机自启动脚本 ...

  10. disable-network-config

    network: {config: disabled}