PAT甲级 1010 Radix (25分)

Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number. Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given. Input Specification: Each input file contains one test case. Each case occupies a line which contains 4 positive integers: ...

March 29, 2020 · 3 min

PAT甲级 1085 Perfect Sequence (25分)

Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respectively. Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence. Input Specification: Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (≤10^5) is the number of integers in the sequence, and p (≤ 10^9 ) is the parameter. In the second line there are N positive integers, each is no greater than 10^9. ...

March 28, 2020 · 2 min

PAT甲级 1038 Recover the Smallest Number (30分)

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87. Input Specification: Each input file contains one test case. Each case gives a positive integer N (≤10^4) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space. ...

March 28, 2020 · 2 min

PAT甲级 1067 Sort with Swap(0, i) (25分)

Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the following way: Swap(0, 1) => {4, 1, 2, 0, 3} Swap(0, 3) => {4, 1, 2, 3, 0} Swap(0, 4) => {0, 1, 2, 3, 4} Now you are asked to find the minimum number of swaps need to sort the given permutation of the first N nonnegative integers. ...

March 27, 2020 · 2 min

PAT乙级 1033 旧键盘打字 (20分)

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 10^5 个字符的串。可用的字符包括字母 [a-z, A-Z]、数字 0-9、以及下划线 _(代表空格)、,、.、-、+(代表上档键)。题目保证第 2 行输入的文字串非空。 注意:如果上档键坏掉了,那么大写的英文字母无法被打出。 输出格式: 在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。 输入样例: 7+IE. 7_This_is_a_test. 输出样例: _hs_s_a_tst 注意点 读入失效键位的时候要注意,可能没有失效的键位,即第一行为空行的情况。这时候不能用 scanf 输入,而要用 cin.getline(str, maxn) 输入字符串。 #include <iostream> #include <cstring> using namespace std; const int maxn = 100001; int main() { int hash_table[256] = {0}; char wrong[257], input[maxn]; cin.getline(wrong, 257); int len = strlen(wrong); for (int i = 0; i < len; i++) { if (wrong[i] >= 'A' && wrong[i] <= 'Z') { wrong[i] = wrong[i] - 'A' + 'a'; } hash_table[wrong[i]] = 1; } scanf("%s", input); len = strlen(input); for (int i = 0; i < len; i++) { if (input[i] >= 'A' && input[i] <= 'Z') { int low = input[i] - 'A' + 'a'; if (hash_table[low] == 0 && hash_table['+'] == 0) { printf("%c", input[i]); } } else if (hash_table[input[i]] == 0) { printf("%c", input[i]); } } printf("\n"); return 0; }

March 26, 2020 · 1 min

Dubbo微服务影院系列(6):Dubbo服务开发(影片模块开发)

章节概要 掌握 API 网关服务聚合功能的实现 掌握 Mybatis-plus 自定义 SQL 实现 掌握 Dubbo 异步调用 服务聚合 服务聚合就是将多个服务调用封装 服务聚合可以简化前端调用方式 服务聚合提供更好的安全性、可扩展性 业务功能开发流程 根据接口文档思考功能列表 实现 API 接口和实体 服务提供者实现 影片模块创建 从 guns-user 拷贝一份重命名为 guns-film,修改相关配置 API 网关功能聚合 优点 六个接口,一次请求,同一时刻节省了5次HTTP请求 同一个接口对外暴露,降低了前后端分离开发的难度和复杂度 缺点: 一次获取数据过多,容易出现问题 如 gateway 中的影片模块的获取首页信息接口,将 filmServiceApi 的多个方法所获得的对象聚合为 FilmIndexVO 对象返回给前端,将原本需要的多个接口聚合为一个 /film/getIndex 接口,避免了前端对不同接口的多次调用。 @RequestMapping(value = "getIndex", method = RequestMethod.GET) public ResponseVO getIndex() { FilmIndexVO filmIndexVO = new FilmIndexVO(); // 获取banner信息 filmIndexVO.setBanners(filmServiceApi.getBanners()); // 获取热映的影片 filmIndexVO.setHotFilms(filmServiceApi.getHotFilms(true, 99, 99, 99, 99, 1, 8)); // 获取即将上映的影片 filmIndexVO.setSoonFilms(filmServiceApi.getSoonFilms(true, 99, 99, 99, 99, 1, 8)); // 获取票房排行榜 filmIndexVO.setBoxRanking(filmServiceApi.getBoxRanking()); // 获取人气榜单 filmIndexVO.setExpectRanking(filmServiceApi.getExpectRanking()); // 获取排行前100影片 filmIndexVO.setTop100(filmServiceApi.getTop()); return ResponseVO.success(IMG_PRE, filmIndexVO); } Mybatis-plus 自定义 SQL 实现 在相应的 Mapper 接口中添加方法 ...

March 22, 2020 · 3 min

PAT甲级 1033 To Fill or Not to Fill (25分)

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked to carefully design the cheapest route to go. Input Specification: Each input file contains one test case. For each case, the first line contains 4 positive numbers: Cmax (≤ 100), the maximum capacity of the tank; D (≤30000), the distance between Hangzhou and the destination city; Davg (≤20), the average distance per unit gas that the car can run; and N (≤ 500), the total number of gas stations. Then N lines follow, each contains a pair of non-negative numbers: Pi, the unit gas price, and Di (≤D), the distance between this station and Hangzhou, for i=1,⋯,N. All the numbers in a line are separated by a space. ...

March 22, 2020 · 3 min

PAT甲级 1095 Cars on Campus (30分)

Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period. ...

March 22, 2020 · 4 min

PAT甲级 1016 Phone Bills (25分)

A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records. ...

March 20, 2020 · 4 min

PAT甲级 1012 The Best Rank (25分)

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student. ...

March 20, 2020 · 3 min