Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

POJ 1578 Instruens Fabulam---模拟

Posted on 2010-09-03 22:37 Uriel 阅读(401) 评论(0)  编辑 收藏 引用 所属分类: POJ模拟
        很久不切模拟,今天比赛的时候手有点生了。。。
        这题断断续续做了两天,被各种事情打乱。。

        纯模拟,方法没什么可说的,这题跟3699有点类似,比3699简单很多,因为是所有的条目都输出,不用筛选。唯一比3699麻烦一点的地方是这题对齐方式有:左对齐,右对齐,居中,这个好办,控制下输出的空格数量就行了。。
        因为有3699的惨痛教训,这题我是一行一行输出。。

       竟然调试完秒出sampl,一次AC~~

        代码比较丑陋。。

//Problem: 1578  User: Uriel 
//Memory: 1364K  Time: 0MS 
//Language: G++  Result: Accepted
//Simulation
//2010.09.03
#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>

struct record{
    
char c[100][100];
}
p[100];

int n;
int maxw[80];
char s[80],lr[80];
bool start;

int main(){
    
int i,j,k,cnt,x;
    
bool flag=false;
    cnt
=0;
    start
=false;
    
while(1){
        
while(1){
            gets(s);
            
if(s[0]=='*'){
                flag
=true;
                
break;
            }

            
else if(s[0]=='<' || s[0]=='>' || s[0]=='='){
                
if(start==false)strcpy(lr,s);
                start
=true;
                
break;
            }

            
else{
                x
=0;
                k
=0;
                
for(i=0;i<strlen(s);i++){
                    
if(s[i]=='&'){
                        
if(k>maxw[x])maxw[x]=k;
                        x
++;
                        k
=0;
                    }

                    
else{
                        p[cnt].c[x][k
++]=s[i];
                    }

                }

                
if(k>maxw[x])maxw[x]=k;
                cnt
++;
            }

        }

        
if(cnt){
            putchar(
'@');
            
for(i=0;i<n;i++){
                
for(j=0;j<maxw[i]+2;j++)putchar('-');
                
if(i<n-1)putchar('-');
            }

            puts(
"@");
            
for(k=0;k<cnt;k++){
                
if(k==1){
                    putchar(
'|');
                    
for(i=0;i<n;i++){
                        
for(j=0;j<maxw[i]+2;j++)putchar('-');
                        
if(i<n-1)putchar('+');
                    }

                    puts(
"|");
                }

                
else{
                    
for(i=0;i<n;i++){
                        putchar(
'|');
                        
if(lr[i]=='<'){
                            printf(
" %s ",p[k].c[i]);
                            
for(j=0;j<maxw[i]-strlen(p[k].c[i]);j++)putchar(' ');
                        }

                        
else if(lr[i]=='='){
                            
for(j=0;j<(maxw[i]-strlen(p[k].c[i]))/2;j++)putchar(' ');
                            printf(
" %s ",p[k].c[i]);
                            
for(j=0;j<maxw[i]-(maxw[i]+strlen(p[k].c[i]))/2;j++)putchar(' ');
                        }

                        
else if(lr[i]=='>'){
                            
for(j=0;j<maxw[i]-strlen(p[k].c[i]);j++)putchar(' ');
                            printf(
" %s ",p[k].c[i]);
                        }

                    }

                    puts(
"|");
                }

            }

            putchar(
'@');
            
for(i=0;i<n;i++){
                
for(j=0;j<maxw[i]+2;j++)putchar('-');
                
if(i<n-1)putchar('-');
            }

            puts(
"@");
        }

        n
=strlen(s);
        strcpy(lr,s);
        
if(!flag){
            x
=0;
            k
=0;
            cnt
=0;
            gets(s);
            memset(p,
0x00,sizeof(p));
            memset(maxw,
0,sizeof(maxw));
            
for(i=0;i<strlen(s);i++){
                
if(s[i]=='&'){
                    
if(k>maxw[x])maxw[x]=k;
                    x
++;
                    k
=0;
                }

                
else{
                    p[cnt].c[x][k
++]=s[i];
                }

            }

            
if(k>maxw[x])maxw[x]=k;
            cnt
++;
            cnt
++;
        }

        
else
            
break;
    }

    
return 0;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理