[Java] 1005. Spell It Right (20)-PAT甲级

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:
12345
Sample Output:
one five

题目大意:给一个非负正数N,计算N的每一位相加的和,然后输出和的每一位的英文读音~

PS:感谢github用户@fs19910227提供的pull request~

 

[Java] 1003. Emergency (25)-PAT甲级

1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) – the number of cities (and the cities are numbered from 0 to N-1), M – the number of roads, C1 and C2 – the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
Sample Output
2 4
题目大意:n个城市m条路,每个城市有救援小组,所有的边的边权已知。给定起点和终点,求从起点到终点的最短路径条数以及最短路径上的救援小组数目之和。如果有多条就输出点权(城市救援小组数目)最大的那个~

PS:感谢github用户@fs19910227提供的pull request~

 

[Java] 1002. A+B for Polynomials (25)-PAT甲级

This time, you are supposed to find A+B where A and B are two polynomials.

Input
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < … < N2 < N1 <=1000.

Output
For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output
3 2 1.5 1 2.9 0 3.2

题目大意:计算A+B的和,A和B都是多项式

PS:感谢github用户@fs19910227提供的pull request~

[Java] 1001. A+B Format (20)-PAT甲级

Calculate a + b and output the sum in standard format — that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input
-1000000 9
Sample Output
-999,991

题目大意:计算A+B的和,然后以每三位加一个”,”的格式输出。

PS:感谢github用户@fs19910227提供的pull request~

[Java] 1001. 害死人不偿命的(3n+1)猜想 (15)-PAT乙级

1001. 害死人不偿命的(3n+1)猜想 (15)
卡拉兹(Callatz)猜想:
对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证(3n+1),以至于有人说这是一个阴谋,卡拉兹是在蓄意延缓美国数学界教学与科研的进展……
我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过1000的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1?
输入格式:
每个测试输入包含1个测试用例,即给出自然数n的值。

输出格式:
输出从n计算到1需要的步数。

输入样例:
3
输出样例:
5

Mac 蓝牙触控板(Magic trackpad)和原来自带的内建触控板同时使用

之前使用Magic trackpad 2时候出了点小问题,发现断开trackpad后依然无法使用内建触控板,导致自己用了一天的鼠标ORZ……然后就想到了能否两个触控板一起使用的功能……果然在辅助功能里面有~(不过似乎朋友的MacBook里这个功能是默认关闭的,不知道为什么我的是默认打开的…)

所以这个问题也可以解决:蓝牙触控板Magic trackpad断开连接后原触控板依然无法使用的问题

系统偏好设置 – 辅助功能 – 鼠标与触控板 – 取消勾选“有鼠标或无线触控板时忽略内建触控板”