首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

【读题】第一个向左其后向右——Center Alignment(CodeForce 5D)

2012-12-16 
【读题】第一个向左然后向右——Center Alignment(CodeForce 5D)来源:点击打开链接纯字符串模拟排版。基本无难

【读题】第一个向左然后向右——Center Alignment(CodeForce 5D)

来源:点击打开链接

纯字符串模拟排版。基本无难度,但是用STRING会出现一点点问题。还是用CHAR更靠谱一些。当然最重要的是读题,第一个向左第二个向右以此类推,所以要添加一个判断的语句来判奇偶行。看测试数据的时候发现了“*”本身是被无视的。。能加个框就行了。。


#include <iostream>#include <cstring>using namespace std;struct Node{string ch;int size;};int main(){Node a[1000];string ch;int max=0;int i=0;while(getline(cin,ch,'\n')){a[i].ch=ch;a[i].size=ch.size();if(ch.size()>max)max=ch.size();i++;}int leftctrl=0;for(int j=0;j<max+2;j++){cout<<"*";}cout<<endl;for(int j=0;j<i;j++){int kongge=max-a[j].size;if(kongge%2==0){cout<<"*";for(int m=0;m<kongge/2;m++)cout<<" ";cout<<a[j].ch;for(int m=0;m<kongge/2;m++)cout<<" ";cout<<"*";cout<<endl;}else{if(leftctrl%2==0){cout<<"*";for(int m=0;m<kongge/2;m++)cout<<" ";cout<<a[j].ch;for(int m=0;m<kongge/2+1;m++)cout<<" ";cout<<"*";cout<<endl;leftctrl++;}else{cout<<"*";for(int m=0;m<kongge/2+1;m++)cout<<" ";cout<<a[j].ch;for(int m=0;m<kongge/2;m++)cout<<" ";cout<<"*";cout<<endl;leftctrl++;}}}for(int j=0;j<max+2;j++){cout<<"*";}cout<<endl;return 0;}


热点排行