UVA 1593: Alignment of Code(模拟 Grade D)
2014-10-17 19:59
357 查看
题意:
格式化代码。每个单词对齐,至少隔开一个空格。
思路:
模拟。求出每个单词最大长度,然后按行输出。
代码:
格式化代码。每个单词对齐,至少隔开一个空格。
思路:
模拟。求出每个单词最大长度,然后按行输出。
代码:
#include <cstdio> #include <cstdlib> #include <cstring> char words[1200][190][90]; int maxLen[190]; char tmp[200]; typedef char * pchar; int readStr(pchar &str, char *out) { int num = 0; 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 = 0; for (i = 0; str[i]; i++) { putchar(str[i]); } for (; i < len; i++) { putchar(' '); } } int main() { char *p; int nowLine = 0; while (gets(tmp)) { p = tmp; int i = 0; while (readStr(p, words[nowLine][i]) != -1) { i++; } nowLine++; } for (int i = 0; i < nowLine; i++) { for (int j = 0; j < 185; j++) { if (strlen(words[i][j]) > maxLen[j]) { maxLen[j] = strlen(words[i][j]); } } } for (int i = 0; i < nowLine; i++) { for (int j = 0; j < 185; j++) { if (strlen(words[i][j]) != 0) { if (j != 0) printf(" "); if (strlen(words[i][j+1])) myprint(words[i][j], maxLen[j]); else printf("%s", words[i][j]); } else break; } printf("\n"); } return 0; }
相关文章推荐
- UVa1593 - Alignment of Code
- UVALive4983 UVa1593 POJ3959 Alignment of Code【字符串流+输入输出+水题】
- 【UVa 1593】Alignment of Code
- Alignment of Code (代码对齐)UVA1593
- Alignment of Code,ACM/ICPC NEERC 2010,UVa 1593
- [UVa 1593] Alignment of Code 代码对齐
- UVA - 1593 Alignment of Code 纯代码功底
- UVA ~ 1593 ~ Alignment of Code (vector+模拟)
- Alignment of Code UVa1593
- Uva1593 Alignment of Code 【vector,stream应用】【习题5-1】
- UVa 1593 Alignment of Code 细节
- UVa 1593 Alignment of code 解题报告
- Alignment of Code UVA - 1593
- UVa 1593 Alignment of Code(字符串)
- UVa 1593 - Alignment of Code
- UVa-1593 - Alignment of Code
- Uva1593 - Alignment of Code
- Uva1593——Alignment of Code
- UVA1593 - Alignment of Code
- UVA - 1593 Alignment of Code