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

PAT甲级 1082 Read Number in Chinese (25分)

Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai. ...

March 19, 2020 · 2 min

PAT甲级 1061 Dating (20分)

Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 – since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time. ...

March 18, 2020 · 3 min

PAT乙级 1010 一元多项式求导 (25分)

设计函数求一元多项式的导数。(注:x^n(n为整数)的一阶导数为nx^{n−1}。) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。 输出格式: 以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 0 0。 输入样例: 3 4 -5 2 6 1 -2 0 输出样例: 12 3 -10 1 6 0 注意点 用 while……EOF 的格式来读入系数和指数(黑框中触发 EOF 要按 ctrl + Z,并回车) 经测试,该题的指数都是非负整数 求导必须从低次项枚举到高次项,否则结果可能为出错 在求导后,当前系数必须清空为0,否则当前无法被后面覆盖 如果求导之后没有任何非零项,需要输出 0 0 #include <cstdio> const int maxn = 1001; int main() { int n[maxn] = {0}, c, e, cnt = 0; while (scanf("%d%d", &c, &e) != EOF) { n[e] = c; } n[0] = 0; for (int i = 1; i < maxn; i++) { n[i - 1] = i * n[i]; n[i] = 0; if (n[i - 1] != 0) { cnt++; } } if (cnt == 0) { printf("0 0"); } else { for (int i = maxn - 1; i >= 0; i--) { if (n[i] != 0) { printf("%d %d", n[i], i); cnt--; if (cnt != 0) { printf(" "); } else { break; } } } } return 0; }

March 17, 2020 · 1 min

PAT甲级 1065 A+B and C (64bit) (20分)

Given three integers A, B and C in [−2^63,2^63], you are supposed to tell whether A+B>C. Input Specification: The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces. Output Specification: For each test case, output in one line Case #X: true if A+B>C, or Case #X: false otherwise, where X is the case number (starting from 1). ...

March 15, 2020 · 2 min

Dubbo微服务影院系列(5):Dubbo基本特性(用户模块开发)

章节概要 学会 API 网关权限验证和其他服务交互 学会开发 SpringBoot 的自定义配置 学会 Dubbo 负载均衡策略选择和使用 修改 Guns 中的 JWT 模块 增加忽略验证 URL 配置 修改返回内容匹配业务 增加 Threadlocal 的用户信息保存 业务功能开发 增加用户服务并提供接口 初步了解 API 网关与服务之间交互的过程 根据接口文档开发用户接口 创建用户表 DROP TABLE IF EXISTS user; CREATE TABLE user( UUID INT PRIMARY KEY AUTO_INCREMENT COMMENT '主键编号', user_name VARCHAR(50) COMMENT '用户账号', user_pwd VARCHAR(50) COMMENT '用户密码', nick_name VARCHAR(50) COMMENT '用户昵称', user_sex INT COMMENT '用户性别 0-男,1-女', birthday VARCHAR(50) COMMENT '出生日期', email VARCHAR(50) COMMENT '用户邮箱', user_phone VARCHAR(50) COMMENT '用户手机号', address VARCHAR(50) COMMENT '用户住址', head_url VARCHAR(50) COMMENT '头像URL', biography VARCHAR(200) COMMENT '个人介绍', life_state INT COMMENT '生活状态 0-单身,1-热恋中,2-已婚,3-为人父母', begin_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间' ) COMMENT '用户表' ENGINE = INNODB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC; insert into user(user_name,user_pwd,nick_name,user_sex,birthday,email,user_phone,address,head_url,life_state,biography) values('admin','0192023a7bbd73250516f069df18b500','管理员',0,'2018-07-31','admin@gmail.com','13888888888','浙江省杭州市西湖区某路某号','cinema/img/head-img.jpg',0,'我是苦逼的管理员'); insert into user(user_name,user_pwd,nick_name,user_sex,birthday,email,user_phone,address,head_url,life_state,biography) values('test','5e2de6bd1c9b50f6e27d4e55da43b917','测试用户',0,'2018-08-20','test@gmail.com','13866666666','测试地址','cinema/img/head-img.jpg',1,'我是测试用户'); 用户服务与网关交互 在 guns 项目中复制一份 guns-gateway 模块并重命名为 guns-user(修改相应子模块和主模块的 pom.xml 等),并在 application.yml 中将其鉴权机制等关闭(网关才需要) ...

March 11, 2020 · 5 min

Dubbo微服务影院系列(4):业务基础环境构建

章节概要 构建基于 Guns + SpringBoot + Dubbo 的框架 学会抽离业务接口 学会 API 网关变形应用 API 网关介绍 API 网关有点类似于设计模式中的 Facade 模式 API 网关一般都是微服务系统中的门面 API 网关是微服务的重要组成部分 API 网关的常见作用 身份验证和安全 审查和检测 动态路由 压力测试 负载均衡(Dubbo 自带) 静态相应处理 Guns 环境构建 导入 guns 项目 创建 guns_rest 数据库 创建 user 表 -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES (1, 'admin'); SET FOREIGN_KEY_CHECKS = 1; 添加 log4j 依赖 <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> 修改 datasource 的 url 修改 application.yml 中 spring 的 datasource 的 url 为 ...

March 9, 2020 · 2 min

Dubbo微服务影院系列(3):环境搭建

基础环境搭建 基于Guns + SpringBoot + Dubbo构建影院平台 Spring + Dubbo SpringBoot + Dubbo 微服务基本概念 Provider:服务提供者 Consumer:服务调用者,调用 Provider 提供的服务实现 同一个服务可以即是 Provider,又是 Consumer 以下可以选用 Spring 或 SpringBoot Spring基础环境构建 项目结构 主模块(Spring-Dubbo-Demo) 在 pom.xml 中添加 dependencies <dependencies> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.9</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.9</version> <type>pom</type> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.6.Final</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.21.0-GA</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!-- spring相关jar --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> 子模块(provider、consumer) 在 resources 中添加 applicationContext.xml(可更改后缀) ...

March 8, 2020 · 3 min