C/C++
moffy_abo
潜心修炼
展开
-
pat甲级 1009. Product of Polynomials (25)
This time, you are supposed to find A*B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information...原创 2017-01-15 12:06:32 · 315 阅读 · 0 评论 -
PAT甲级 1098. Insertion or Heap Sort (25)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, f...原创 2017-01-20 09:54:21 · 330 阅读 · 0 评论 -
PAT甲级 1097. Deduplication on a Linked List (25)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or a...原创 2017-01-20 11:05:50 · 303 阅读 · 0 评论 -
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 ...原创 2017-01-20 16:38:49 · 383 阅读 · 0 评论 -
PAT甲级 1095. Cars on Campus (30)
Zhejiang University has 6 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 a...原创 2017-09-03 23:31:14 · 258 阅读 · 0 评论 -
PAT甲级 1108. Finding Average (20)
The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A "legal" input is a re...原创 2017-01-18 17:07:18 · 1175 阅读 · 1 评论 -
PAT甲级 1139. First Contact (30)
Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly i...原创 2018-02-06 17:50:35 · 1505 阅读 · 0 评论 -
PAT甲级 1138. Postorder Traversal (25)
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal se...原创 2018-02-06 22:52:28 · 330 阅读 · 0 评论 -
PAT甲级 1137. Final Grading (25)
For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from...原创 2018-02-06 23:08:22 · 361 阅读 · 0 评论 -
读几个小程序了解c++:Part 01(构造函数、析构函数、指针、静态数据成员)
以前学c++的时候光打酱油了,现在抽出几天时间把c++系统复习一下,每天敲一个小程序记录下自己学习的东西。#include <cstdio>#include <climits>#include <algorithm>#include <cstring>#include <iostream>using namespace std;...原创 2018-02-27 18:23:28 · 195 阅读 · 0 评论 -
PAT甲级 1079. Total Sales of Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the ...原创 2018-02-19 21:19:07 · 227 阅读 · 0 评论 -
PAT甲级 1135. Is It A Red-Black Tree (30) 建树+深搜
There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black.(2) The root is black.(3) Every leaf ...原创 2018-02-28 20:27:37 · 401 阅读 · 0 评论 -
读几个小程序了解c++:Part 02(友元、常类型)
#include <cstring>#include <iostream>using namespace std;/* 类的主要特点是信息隐藏与封装,友元函数是为了实现在类的外部访 问类的私人成员(或保护成员),是一扇通向私人(保护)成员的后 门,使得普通函数也可以访问封装在某一类的信息。*/class Girl; ///提前声明Girl类cla...原创 2018-02-28 20:29:55 · 169 阅读 · 0 评论 -
PAT 甲级1131. Subway Map (30)
In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with you...原创 2018-03-02 21:07:11 · 1020 阅读 · 0 评论 -
读几个小程序了解c++:Part 03(派生类和继承)
#include <iostream>using namespace std;/// 基类中的成员 公有派生类 私有派生类 保护派生类/// 私有成员 不可直接访问 不可直接访问 不可直接访问/// 公有成员 public private protected/// 保护成...原创 2018-03-02 21:08:09 · 215 阅读 · 0 评论 -
PAT甲级 1099. Build A Binary Search Tree (30)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right subtre...原创 2017-01-19 21:50:29 · 353 阅读 · 0 评论 -
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 Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, resp...原创 2017-01-19 17:20:16 · 311 阅读 · 0 评论 -
PAT甲级 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...原创 2017-01-19 16:34:15 · 269 阅读 · 0 评论 -
pat甲级 1122. Hamiltonian Cycle (25)
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a "Hamiltonian cycle".In this problem, you are supposed to tell if a given cycle原创 2017-01-16 11:11:40 · 869 阅读 · 0 评论 -
pat甲级 1121. Damn Single (25)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification:Each inpu原创 2017-01-16 12:21:00 · 679 阅读 · 0 评论 -
PAT甲级 1119. Pre- and Post-order Traversals (30)
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder ...原创 2017-01-16 19:03:32 · 401 阅读 · 0 评论 -
PAT甲级 1118 Birds in Forest (25)
Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...原创 2017-01-17 10:54:56 · 691 阅读 · 0 评论 -
PAT甲级 1115. Counting Nodes in a BST (30)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than or equal to the node's key.The ...原创 2017-01-17 14:37:46 · 331 阅读 · 0 评论 -
PAT甲级 1111. Online Map (30)
Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...原创 2017-01-18 11:47:38 · 1291 阅读 · 0 评论 -
PAT甲级 1110. Complete Binary Tree (25)
Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (<=20) wh...原创 2017-01-18 16:59:20 · 292 阅读 · 0 评论 -
PAT甲级 1109. Group Photo (25)
Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The number of people in each row must be N/K (round down to the nearest integer)...原创 2017-01-18 17:04:54 · 377 阅读 · 0 评论 -
PAT甲级 1107. Social Clusters (30)
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A "social cluster" is a set of people who have some of th...原创 2017-01-18 21:46:31 · 220 阅读 · 0 评论 -
PAT甲级 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the ...原创 2017-01-18 21:54:21 · 375 阅读 · 0 评论 -
PAT甲级 1105. Spiral Matrix (25)
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in...原创 2017-01-18 22:18:40 · 278 阅读 · 0 评论 -
PAT甲级 1104. Sum of Number Segments (20)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) ...原创 2017-01-18 22:47:40 · 217 阅读 · 0 评论 -
PAT甲级 1103. Integer Factorization (30)
The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K-P factorization of N for any positive...原创 2017-01-19 15:10:17 · 276 阅读 · 0 评论 -
PAT甲级 1102. Invert a Binary Tree (25)
The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.Now it's your turn to prove...原创 2017-01-19 16:04:57 · 258 阅读 · 0 评论 -
读几个小程序了解c++:Part 04(多态)
#include "iostream"using namespace std;///多态是指不同子类间的同名函数表现形式不同///实现多态可以让变量根据类型选择合适的同名函数class Student {public: Student(string n, int a, int h, int w); Student(){} void set_(string n, int a, i...原创 2018-03-11 11:13:31 · 336 阅读 · 0 评论