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> # ...
随机推荐
- WCF入门二[WCF的配置文件]
一.概述 往往在很多项目中数据库连接字符串.变量和一些动态的加载类会写在配置文件中.WCF也会在配置文件中写入一些配置参数,比如服务的地址.服务用于发送和接收消息的传输和消息编码等,通过配置文件可以灵 ...
- Android Stadio 相关
这几天,电脑坏了.重装系统,慢慢的学到了很多Android stadio 的相关知识.总结一下吧: 1.gradle 编译工具:在工程的gradle/wrapper/gradle–wrapper.pr ...
- 页面引入外部字体ttf,如何提取所需要的ttf字体或者加载过慢的解决方法-1127更新
最近几天编写手机端的页面之后,文中需要华文行楷字体,在网上下载后,引入到了自己的前端页面,以为没有什么事了,继续码代码 @font-face { font-family:huawen; src: ur ...
- ajax跨域请求_url:http://XXX
利用别的项目提供的一个接口,传入用户名和密码,根据返回的结果判断登陆成功与否. 不经过后台,在js中用ajax实现.对ajax而言,发送跨域请求,与一般写法不同. 如果支持jsonp,则将dataTy ...
- 容器技术的落地还要依靠SDN
容器能够实现新应用程序的快速部署,代表着目前IT开发社区的最热门趋势之一.然而,想要实现容器部署生产环境,IT人员还需要使用SDN技术,在分布式微应用程序之间实现可扩展.可管理且安全的通信. 什么是容 ...
- Android学习记录(2)—Android中数据库的常见操作
android中数据库操作是非常常见了,我们会经常用到,操作的方法也有很多种形式,这里我就把最常见的两种形式记录下来了,以备以后用到方便查看.我就不写注释和解释了,因为android数据库的操作和其它 ...
- save?commit
数据库的隐式提交 先看一段SQL,最后一条SQL的输出你认为是什么? 1 2 3 4 5 6 7 SET AUTOCOMMIT = 1; BEGIN; INSERT INTO t1 VALUES (1 ...
- Python学习3,列表
列表就是能够包含几个或者上千上万个元素,对我这种新手来说应该是最重要的了! _author_ = "Happyboy" shopping = ['Iphone','Huawei', ...
- cloud-init介绍及源码解读
https://zhuanlan.zhihu.com/p/27664869 知乎大神写的
- MVC学习笔记---WebViewPage(nop等开源项目的@T)
http://www.cnblogs.com/gyche/p/5597491.html http://www.cnblogs.com/Alex80/p/5369042.html http://www. ...