题意:

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

思路:

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

代码:

#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. 3336 /P1948电话网络(二分答案)

    3336 电话网络  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold       题目描述 Description 由于地震使得连接汶川县城电话线全部损坏,假如你是 ...

  2. P2344 奶牛抗议

    P2344 奶牛抗议 题目背景 Generic Cow Protests, 2011 Feb 题目描述 约翰家的N 头奶牛正在排队游行抗议.一些奶牛情绪激动,约翰测算下来,排在第i 位的奶牛的理智度为 ...

  3. 关于update 表名 set 字段1 = 值1 and 字段2 = 值2的执行结果说明

    技术交流群: 233513714 如果执行了以下的语句,则brand等于‘OPPO’条件所对应的数据不会做改变,但是sequence_brand列除brand = 'OPPO'之外的所有数据都会变为0 ...

  4. TerminateProcess

    Remarks The TerminateProcess function is used to unconditionally cause a process to exit. The state ...

  5. git命令行操作详解

    目录 1.常用操作 1.1 新建代码库 1.2 配置 1.3 remote管理 1.4 添加和撤销操作 1.5 代码提交 1.6 分支操作 1.7 查看信息 1.8 pull操作 1.9 push操作 ...

  6. istringstream输入数据到数组

    istringstream iss(line); ; while (!(iss >> dat[n]).fail()) n++;

  7. Mac 小技巧

    本文的大部分技巧来自于池建强老师的<MacTalk.人生元编程>,感谢他的辛苦付出,本文多系整理而已. 终端输入说英语 说英语时我们当然希望有标准发音.在Mac中不需要字典,直接在终端里输 ...

  8. Linux/Unix中系统级IO

    Linux/unix I/O:将设备映射为文件的方式,允许Unix内核引出一个简单.低级的应用接口. Linux/unix IO的系统调用函数很简单,它只有5个函数:open(打开).close(关闭 ...

  9. python负数除法与模运算

    1.负数除法: >>> print 45/76>>> print -45/7-7 >>> print 45/-7-7 >>> p ...

  10. ASP.NET Core 2.1 源码学习之 Options[1]:Configure 【转】

    原文链接:https://www.cnblogs.com/RainingNight/p/strongly-typed-options-configure-in-asp-net-core.html 配置 ...