Alignment of Code POJ 3959 HDU 3753
来源:互联网 发布:arp mac绑定 编辑:程序博客网 时间:2024/05/17 03:26
这题在POJ、HDU、UVAlive上都有出现,是Northeastern Europe 2010区域赛的A题,是比较水的,但是我在HDU上过这题还是废了些功夫的,尤其是数组大小问题,在HDU上word[100][80]是会被WA掉的,但开word[100][85]是会被AV(ACCESS_VIOLATION)的,狠心开到word[100][200]才能AC,只能说HDU上的数据改的有点离谱,最后说一下UVAlive吧,是最无语的,UVAlive上这场比赛的题用return 0;全是可以交的过的,也不知道这UVAlive是怎么搞的!
//以下是POJ3959的代码,注意:POJ是没有case的。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct _Line{
char word[100][85];
int cc_word;
void Init()
{
cc_word = 0;
for(int i = 0;i < 100;i++)
memset(word[i],0,sizeof(word[i]));
}
}Line;
Line line[1010];
inline bool judge(char ch)
{
if(ch >= 33 && ch <= 126) return true;
return false;
}
int main()
{
freopen("in.txt","r",stdin);
//freopen("outb.txt","w",stdout);
int cases;
char str[190];
memset(str,0,sizeof(str));
int cc_line = 0;
while(gets(str)!=NULL)
{
int len = strlen(str);
int cc = 0;
bool flag = false;
for(int i = 0;i <= len;i++)
{
if(flag && !judge(str[i]))
{
line[cc_line].word[line[cc_line].cc_word][cc] = 0;
cc = 0;
line[cc_line].cc_word++;
flag = false;
}
else if(!flag && !judge(str[i]))
continue;
else
{
line[cc_line].word[line[cc_line].cc_word][cc++] = str[i];
flag = true;
}
}
cc_line ++;
}
int max_word = 0;
for(int i = 0;i < cc_line;i++)
if(line[i].cc_word > max_word)
max_word = line[i].cc_word;
for(int j = 0;j < max_word;j++)
{
int max_width = 0;
for(int i = 0;i < cc_line;i++)
{
if(line[i].cc_word <= j)
continue;
int len_line = strlen(line[i].word[j]);
if(len_line > max_width)
max_width = len_line;
}
for(int i = 0;i < cc_line;i++)
{
if(line[i].cc_word <= j || line[i].cc_word-1 == j)
continue;
int len_line = strlen(line[i].word[j]);
for(int k = len_line;k < max_width;k++)
line[i].word[j][k] = ' ';
line[i].word[j][max_width] = 0;
}
}
for(int i = 0;i < cc_line;i++)
{
printf("%s",line[i].word[0]);
for(int j = 1;j < line[i].cc_word;j++)
printf(" %s",line[i].word[j]);
puts("");
}
return 0;
}
- Alignment of Code POJ 3959 HDU 3753
- hdu 3753 Alignment of Code
- hdu 3753 字符串 Alignment of Code
- Alignment of Code(hdu)
- HDU 3753 Alignment of Code 字符串对其 stl
- HDU 3753 Alignment of Code 字符串对其 stl
- UVA1593 - Alignment of Code
- 1593 - Alignment of Code
- 1593 - Alignment of Code
- UVa1593 - Alignment of Code
- UVA_1593: Alignment of Code
- Uva Alignment of Code
- Uva1593 Alignment of Code
- Alignment of Code UVA
- Alignment of Code
- Alignment of Code UVA
- UVa1593 Alignment of Code
- UVa 1593 Alignment of Code
- jquery 对asp.net CheckBoxList全选、反选
- android http /https协议学习
- telerik控件学习资料
- 基于libGPE读写KML文件的研究
- PHP图片上传程序(完整版)
- Alignment of Code POJ 3959 HDU 3753
- JQuery回到顶部(Scroll to Top)
- Veloctiy安全输出帮助
- iphone 提示(弹出)框的使用
- 设计模式之(十七)状态模式State
- 进程性能检测命令gprof和top
- Sql 查询当天、本周、本月记录
- SendMessage 和 PostMessage 的区别
- DELPHI直接分析Oracle tnsnames.ora提取服务器列表