PAT甲级 1100 Mars Numbers (20分)

People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively. For the next higher digit, Mars people name the 12 numbers as “tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou”, respectively. For examples, the number 29 on Earth is called “hel mar” on Mars; and “elo nov” on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems. ...

April 6, 2020 · 2 min

Dubbo微服务影院系列(8):Dubbo服务开发(订单模块开发)

章节概要 完成订单模块业务开发 完成限流和熔断、降级相关内容 Dubbo 特性之分组、聚合和版本控制 订单模块问题 订单模块的横向和纵向分表如何解决? 服务限流如何处理? 服务熔断和降级? 如何保证多版本的蓝绿上线? 横向拆分和纵向拆分 Dubbo 服务分组 官方文档:https://dubbo.apache.org/zh-cn/docs/user/demos/service-group.html 当一个接口有多种实现时,可以用 group 区分。 服务 <dubbo:service group="feedback" interface="com.xxx.IndexService" /> <dubbo:service group="member" interface="com.xxx.IndexService" /> 引用 <dubbo:reference id="feedbackIndexService" group="feedback" interface="com.xxx.IndexService" /> <dubbo:reference id="memberIndexService" group="member" interface="com.xxx.IndexService" /> 任意组: <dubbo:reference id="barService" interface="com.foo.BarService" group="*" /> Dubbo 分组聚合 https://dubbo.apache.org/zh-cn/docs/user/demos/group-merger.html 按组合并返回结果,比如菜单服务,接口一样,但有多种实现,用 group 区分,现在消费方需从每种 group 中调用一次返回结果,合并结果返回,这样就可以实现聚合菜单项。 配置 搜索所有分组 <dubbo:reference interface="com.xxx.MenuService" group="*" merger="true" /> 合并指定分组 <dubbo:reference interface="com.xxx.MenuService" group="aaa,bbb" merger="true" /> 指定方法合并结果,其它未指定的方法,将只调用一个 Group <dubbo:reference interface="com.xxx.MenuService" group="*"> <dubbo:method name="getMenuItems" merger="true" /> </dubbo:reference> 某个方法不合并结果,其它都合并结果 <dubbo:reference interface="com.xxx.MenuService" group="*" merger="true"> <dubbo:method name="getMenuItems" merger="false" /> </dubbo:reference> 指定合并策略,缺省根据返回值类型自动匹配,如果同一类型有两个合并器时,需指定合并器的名称 <dubbo:reference interface="com.xxx.MenuService" group="*"> <dubbo:method name="getMenuItems" merger="mymerge" /> </dubbo:reference> 指定合并方法,将调用返回结果的指定方法进行合并,合并方法的参数类型必须是返回结果类型本身 <dubbo:reference interface="com.xxx.MenuService" group="*"> <dubbo:method name="getMenuItems" merger=".addAll" /> </dubbo:reference> Dubbo 多版本 当一个接口实现,出现不兼容升级时,可以用版本号过渡,版本号不同的服务相互间不引用。 可以按照以下的步骤进行版本迁移: 在低压力时间段,先升级一半提供者为新版本 再将所有消费者升级为新版本 然后将剩下的一半提供者升级为新版本 配置 老版本服务提供者配置: <dubbo:service interface="com.foo.BarService" version="1.0.0" /> 新版本服务提供者配置: <dubbo:service interface="com.foo.BarService" version="2.0.0" /> 老版本服务消费者配置: <dubbo:reference id="barService" interface="com.foo.BarService" version="1.0.0" /> 新版本服务消费者配置: ...

April 5, 2020 · 2 min

PAT甲级 1060 Are They Equal (25分)

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×105 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine. Input Specification: Each input file contains one test case which gives three numbers N, A and B, where N (<100) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 10100, and that its total digit number is less than 100. ...

April 4, 2020 · 2 min

PAT甲级 1039 Course List for Student (25分)

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query. Input Specification: Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤40,000), the number of students who look for their course lists, and K (≤2,500), the total number of courses. Then the student name lists are given for the courses (numbered from 1 to K) in the following format: for each course i, first the course index i and the number of registered students N i (≤200) are given in a line. Then in the next line, N i student names are given. A student name consists of 3 capital English letters plus a one-digit number. Finally the last line contains the N names of students who come for a query. All the names and numbers in a line are separated by a space. ...

April 3, 2020 · 3 min

PAT甲级 1096 Consecutive Factors (20分)

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors. Input Specification: Each input file contains one test case, which gives the integer N (1<N<2^{31}). ...

April 2, 2020 · 2 min

PAT甲级 1078 Hashing (25分)

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSize where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions. Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user. ...

April 2, 2020 · 2 min

PAT甲级 1081 Rational Sum (20分)

Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positive integer N (≤100), followed in the next line N rational numbers a1/b1 a2/b2 ... where all the numerators and denominators are in the range of long int. If there is a negative number, then the sign must appear in front of the numerator. ...

April 1, 2020 · 2 min

PAT乙级 1008 数组元素循环右移问题 (20分)

一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A0 A1 ⋯A N−1 )变换为(A N−M ⋯A N−1 A 0 A 1⋯A N−M−1 )(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法? ...

March 31, 2020 · 2 min

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

章节概要 完成影院模块业务开发 修改全局异常返回 学习 Dubbo 特性:结果缓存,连接和并发控制 Dubbo 结果缓存 官方文档:https://dubbo.apache.org/zh-cn/docs/user/demos/result-cache.html 用于加速热门数据的访问速度,Dubbo 提供声明式缓存,以减少用户加缓存的工作量。 缓存类型 lru 基于最近最少使用原则删除多余缓存,保持最热的数据被缓存。 threadlocal 当前线程缓存,比如一个页面渲染,用到很多 portal,每个 portal 都要去查用户信息,通过线程缓存,可以减少这种多余访问。 配置 <dubbo:reference interface="com.foo.BarService" cache="lru" /> 或: <dubbo:reference interface="com.foo.BarService"> <dubbo:method name="findBar" cache="lru" /> </dubbo:reference> 了解 Dubbo 结果缓存与 Redis 缓存等的区别: Dubbo 结果缓存是本地缓存,保存在当前 JVM 中,多台机器存储多份缓存。适合数据量小的数据,存储在本地占用资源少,而且速度较快。 Redis 缓存则是分布式缓存,多台机器共享缓存。 小数据量的可以放在 Dubbo 结果缓存中,需要计算和共享的缓存数据可以放在 Redis 中。 Dubbo 连接、并发控制 Dubbo 可以对连接、并发数量进行控制 超出部分以错误形式返回 Dubbo 连接控制 官方文档:https://dubbo.apache.org/zh-cn/docs/user/demos/config-connections.html 服务端连接控制 限制服务器端接受的连接不能超过 10 个: <dubbo:provider protocol="dubbo" accepts="10" /> 或 <dubbo:protocol name="dubbo" accepts="10" /> 客户端连接控制 限制客户端服务使用连接不能超过 10 个(如果是长连接,比如 Dubbo 协议,connections 表示该服务对每个提供者建立的长连接数): <dubbo:reference interface="com.foo.BarService" connections="10" /> 或 <dubbo:service interface="com.foo.BarService" connections="10" /> 如果 dubbo:service 和 dubbo:reference 都配了 connections,dubbo:reference 优先。 ...

March 30, 2020 · 1 min

PAT甲级 1049 Counting Ones (30分)

The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12. Input Specification: Each input file contains one test case which gives the positive N (≤230). Output Specification: For each test case, print the number of 1’s in one line. ...

March 30, 2020 · 1 min