1031. Hello World for U (20)

来源:互联网 发布:淘宝steam离线游戏 编辑:程序博客网 时间:2024/05/28 20:20

点击打开链接

貌似n=9错了

#include <iostream>#include <stdio.h>#include <string.h>#include <string>using namespace std;char c[10000];char s[10000][10000];int main(){freopen("in.txt","r",stdin);gets(c);int n=strlen(c)-2;int max=0;int heng;for(int i=1;i<strlen(c);i++){heng=strlen(c)-2*i;if(heng>=3 && heng<=n &&  i<=heng){max=i;}}heng=strlen(c)-2*max;//max即为n1的值,不包括最后一行int cnt=0;for(int i=0;i<=max;i++){for(int j=0;j<=heng;j++){if(j==heng){s[i][j]='\n';}else{s[i][j]=' ';}}}for(int i=0;i<max;i++){s[i][0]=c[cnt++];}for(int i=0;i<heng;i++){s[max][i]=c[cnt++];}for(int i=max-1;i>=0;i--){s[i][heng-1]=c[cnt++];}for(int i=0;i<=max;i++){printf("%s",s[i]);}return 0;}


0 0
原创粉丝点击