题目

PAT A1031 Hello World for U

code

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
    char str[100],ans[40][40];
    scanf("%s",str);
    int N;
    N=strlen(str);
    int n1=(N+2)/3,n3=n1,n2=N+2-n1-n3;
    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n2;j++){
            ans[i][j]=' ';
        }
    }
    int pos=0;
    for(int i=1;i<=n1;i++){
        ans[i][1]=str[pos++];
    }
    for(int j=2;j<=n2;j++){
        ans[n1][j]=str[pos++];
    }
    for(int i=n3-1;i>=1;i--){
        ans[i][n2]=str[pos++];
    }
    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n2;j++){
            printf("%c",ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}

总结

  1. PAT A1031 Hello World for U

PAT A1031 Hello World for U

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2021-12-07
  • 2021-04-12
  • 2021-09-05
  • 2022-01-23
  • 2021-07-16
  • 2022-01-22
猜你喜欢
  • 2022-02-25
  • 2021-10-05
  • 2022-01-15
  • 2021-09-16
  • 2021-05-11
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案