PAT 1031 Hello World for U

#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

char line[82];
char space[82];

int main() {
    scanf("%s", line);
    int len = strlen(line);
    int side_size = (len + 2) / 3 - 1;
    int last_size = len - side_size * 2;
    int space_size= last_size - 2;

    for (int i=0; i<space_size; i++) {
        space[i] = ‘ ‘;
    }

    const char* p = line;
    const char* q = line + len - 1;
    for (int i=0; i<side_size; i++) {
        printf("%c%s%c\n", *p++, space, *q--);
    }
    for (int i=0; i<last_size; i++) {
        printf("%c", *p++);
    }

    return 0;
}

真的是helloworld

时间: 2024-08-08 01:29:30

PAT 1031 Hello World for U的相关文章

PAT 1031

简单题,字符串处理,注意index就可以了 1 import java.util.*; 2 import java.io.*; 3 4 class FastReader{ 5 BufferedReader reader; 6 StringTokenizer tokenizer; 7 8 public FastReader(InputStream stream){ 9 reader = new BufferedReader(new InputStreamReader(stream), 1 <<

PAT 1031. 查验身份证(15)

一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}:然后将计算的和对11取模得到值Z:最后按照以下关系对应Z值与校验码M的值: Z:0 1 2 3 4 5 6 7 8 9 10 M:1 0 X 9 8 7 6 5 4 3 2 现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码. 输入格式: 输入第一行给出正整数N(<= 10

PAT乙级1031

题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 题解 emmm.对于每个身份证号,判断前17位是否合法,并计算其与对应权重积之和,最后判断校验位是否合法. // PAT BasicLevel 1031 // https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 #include

PAT Basic 1031

1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}:然后将计算的和对11取模得到值Z:最后按照以下关系对应Z值与校验码M的值: Z:0 1 2 3 4 5 6 7 8 9 10\ M:1 0 X 9 8 7 6 5 4 3 2 现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码. 输

PAT——乙级1006:换个格式输出整数&amp;乙级1021:个位数统计&amp;乙级1031:查验身份证

1006 换个格式输出整数 (15 point(s)) 让我们用字母 B 来表示"百".字母 S 表示"十",用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数.例如 234 应该被输出为 BBSSS1234,因为它有 2 个"百".3 个"十".以及个位的 4. 输入格式: 每个测试输入包含 1 个测试用例,给出正整数 n(<1000). 输出格式: 每个测试用例的

PAT:1031. 查验身份证(15) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char M[15]={'1','0','X','9','8','7','6','5','4','3','2'}; int n; bool TAG=true; //是否全都没问题的标志 scanf("%d",

PAT 甲级 1031 Hello World for U

https://pintia.cn/problem-sets/994805342720868352/problems/994805462535356416 Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r lowo That is, the cha

【PAT甲级】1031 Hello World for U (20 分)

题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是' ',空格的ascii是32,初读题面时并没有看到要输出空格,因为打印0其实效果看起来好像一样... 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;string s;char a[87][87

PAT Advanced 1031 Hello World for U (20分)

Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r lowo That is, the characters must be printed in the original order, starting top-down from the left