贺巩山的博客

没有伞的孩子更要努力奔跑


  • 首页

  • 文件系统

  • Linux运维

  • 剑指Offer

  • LeetCode题解

  • PAT甲级题解

  • PAT乙级题解

  • CCF CSP题解

  • 分类

  • 标签

  • 归档

  • 书单

  • 关于

  • 搜索

PAT甲级 1058.A+B in Hogwarts (20 分)

发表于 2019-04-22 | 更新于 2019-04-22 | 分类于 pat甲级
字数统计: 437

If you are a fan of Harry Potter, you would know the world of magic has its own currency system – as Hagrid explained it to Harry, “Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it’s easy enough.” Your job is to write a program to compute A+B where A and B are given in the standard form of Galleon.Sickle.Knut (Galleon is an integer in [0,10^7], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).

阅读全文 »

PAT甲级 1027.Colors in Mars (20 分)

发表于 2019-04-21 | 更新于 2019-04-21 | 分类于 pat甲级
字数统计: 350

People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.

阅读全文 »

PAT甲级 1019.General Palindromic Number (20 分)

发表于 2019-04-20 | 更新于 2019-04-20 | 分类于 pat甲级
字数统计: 532

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits $a_i$ as $∑_{i=0}^k(a_i b^i)$. Here, as usual, 0≤$a_i$<b for all i and $a_k$ is non-zero. Then N is palindromic if and only if $a_i=a_{k−i}$ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

阅读全文 »

PAT乙级 1037.在霍格沃茨找零钱 (20 分)

发表于 2019-04-19 | 更新于 2019-04-19 | 分类于 pat乙级
字数统计: 463

如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱 P 和他实付的钱 A,你的任务是写一个程序来计算他应该被找的零钱。

阅读全文 »

“进制转换”编程题总结

发表于 2019-04-18 | 更新于 2019-04-18 | 分类于 程序设计
字数统计: 473

在日常生活中我们一般使用十进制数字,而计算机使用的却是二进制。此外,常见的进制还有八进制、十六进制等。对于两个不同进制,应该如何进行相互转换呢?这里总结下该问题的解题思路。

对于一个P进制的数,如果要转换为Q进制(2 ≤ P , Q ≤ 16),可以分为两步:

(1)将P进制数x转换为十进制数y。

(2)将十进制数y转换为Q进制数z。

阅读全文 »

“日期处理”编程题总结

发表于 2019-04-18 | 更新于 2019-04-18 | 分类于 程序设计
字数统计: 1.1k

日期处理是一类令人感到头疼的编程题,这里总结下该问题的解题思路。

阅读全文 »

PAT乙级 1022.D进制的A+B (20 分)

发表于 2019-04-17 | 更新于 2019-04-17 | 分类于 pat乙级
字数统计: 203

输入两个非负 10 进制整数 A 和 B (≤2^30−1),输出 A+B 的 D (1<D≤10)进制数。

阅读全文 »

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

发表于 2019-04-15 | 更新于 2019-04-15 | 分类于 pat甲级
字数统计: 481

Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:

1
2
3
4
h  d
e l
l r
lowo

That is, the characters must be printed in the original order, starting top-down from the left vertical line with n1characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible – that is, it must be satisfied that n1=n3=max { k | k≤n2 for all 3≤n2≤N } with n1+n2+n3−2=N.

阅读全文 »

PAT乙级 1027.打印沙漏 (20 分)

发表于 2019-04-14 | 更新于 2019-04-15 | 分类于 pat乙级
字数统计: 647

本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印

1
2
3
4
5
*****
***
*
***
*****

所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。

给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。

阅读全文 »

PAT乙级 1036.跟奥巴马一起编程 (15 分)

发表于 2019-04-12 | 更新于 2019-04-13 | 分类于 pat乙级
字数统计: 469

美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014 年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!

阅读全文 »
1…394041…49
Gongshan He

Gongshan He

490 日志
62 分类
89 标签
GitHub 微博 知乎 Linkedin E-Mail
友情链接
  • 卢明冬的博客
  • lipixun
  • 柳婼 の blog
  • 心灵港
  • Liudeyin
© 2016 — 2023 Gongshan He
访问人数 总访问量 次