C++
文章平均质量分 78
要做小太阳
从小白到大白的进阶之路!
展开
-
关于逻辑运算符 && ,|| 的巧用方式
逻辑与 &&&& 会先判断左边的值是否为真。如果为假,那么整个表达式毫无疑问也为假。如果为真,那就还需要判断右值,才能知道整个式子的值。这个时候判断右值的过程就起了一个if的作用,可以利用这个过程判断右边表达式是否为真。下面代码:/*不用任何循环语句,不用if,来实现1+2+3+...+10的值*/ #include <iostream> using n...转载 2018-03-03 14:46:49 · 714 阅读 · 1 评论 -
PAT (Advanced Level) Practice 1115 Counting Nodes in a BST (30 分)
编程题 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 key...原创 2018-11-09 11:01:09 · 110 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1119 Pre- and Post-order Traversals (30 分)
编程题 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 inord...原创 2018-11-09 11:07:53 · 123 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1004 Counting Leaves (30 分)
编程题 1004 Counting Leaves (30 分) A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Specification: Each input file contain...原创 2018-11-02 10:28:18 · 137 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1020 Tree Traversals (25 分)
编程题 1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level or...原创 2018-11-02 15:31:45 · 122 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1053 Path of Equal Weight (30 分)
编程题 1053 Path of Equal Weight (30 分) Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weigh...原创 2018-11-04 23:29:31 · 133 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1034 Head of a Gang (30 分)
编程题 1034 Head of a Gang (30 分) One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight ...原创 2018-11-13 23:41:31 · 130 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1076 Forwards on Weibo (30 分)
编程题 1076 Forwards on Weibo (30 分) Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is forme...原创 2018-11-16 00:16:31 · 134 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1021 Deepest Root (25 分)
编程题 1021 Deepest Root (25 分) A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that results in...原创 2018-11-12 19:16:08 · 125 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1072 Gas Station (30 分)
编程题 1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it mu...原创 2018-11-14 21:03:16 · 143 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1013 Battle Over Cities (25 分)
编程题 1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed...原创 2018-11-14 23:33:55 · 151 阅读 · 0 评论 -
C++——二维vector初始化
1、定义时初始化 vector<vector<int> > v(n, vector<int>(m, num)); //n行m列,初始化数值num vector<vector<int> > v(0, vector<int> (0)); //不确定行列数 vector<vector<int&am原创 2019-02-22 21:22:18 · 2274 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1106 Lowest Price in Supply Chain (25 分)
编程题 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....原创 2018-11-09 10:57:28 · 159 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1102 Invert a Binary Tree (25 分)
编程题 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 whiteboar...原创 2018-11-09 10:27:59 · 137 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1094 The Largest Generation (25 分)
编程题 1094 The Largest Generation (25 分) A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generat...原创 2018-11-09 10:21:55 · 103 阅读 · 0 评论 -
三目运算嵌套寻找最大值
问题:寻找三个数a,b,c中的最大值。代码:#include<iostream> using namespace std; int main(){ int a,b,c,d,max; cout<<"请输入三个数字:"; cin>>a>>b>>c; max=(d=a>=b?a:b)>=c?d:转载 2018-03-03 15:04:38 · 435 阅读 · 0 评论 -
C++ 随机数
C++ 随机数在许多情况下,需要生成随机数。关于随机数生成器,有两个相关的函数。一个是 rand(),该函数只返回一个伪随机数。生成随机数之前必须先调用 srand() 函数。下面是一个关于生成随机数的简单实例。实例中使用了 time() 函数来获取系统时间的秒数,通过调用 rand() 函数来生成随机数:实例#include <iostream>#include <ctime&...转载 2018-03-03 15:28:34 · 169 阅读 · 0 评论 -
C++ 传递数组给函数
C++ 不允许向函数传递一个完整的数组作为参数,但是,您可以通过指定不带索引的数组名来传递一个指向数组的指针。如果您想要在函数中传递一个一维数组作为参数,您必须以下面三种方式来声明函数形式参数,这三种声明方式的结果是一样的,因为每种方式都会告诉编译器将要接收一个整型指针。同样地,您也可以传递一个多维数组作为形式参数。方式 1形式参数是一个指针:void myFunction(int *param)...转载 2018-03-04 13:13:25 · 470 阅读 · 0 评论 -
C++ STL 教程之向量容器实例
C++ STL(标准模板库)是一套功能强大的 C++ 模板类,提供了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量、链表、队列、栈。C++ 标准模板库的核心包括以下三个组件:组件描述容器(Containers)容器是用来管理某一类对象的集合。C++ 提供了各种不同类型的容器,比如 deque、list、vector、map 等。算法(Algorithms)算法作...转载 2018-03-05 21:09:33 · 345 阅读 · 0 评论 -
PAT (Basic Level) Practise (中文)1015. 德才论 (25)
1015. 德才论 (25)时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Li宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:...原创 2018-03-05 22:37:14 · 135 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1107 Social Clusters (30 分)
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...原创 2018-11-01 15:18:30 · 142 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1114 Family Property (25 分)
编程题 1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, w...原创 2018-11-01 20:49:50 · 108 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1118 Birds in Forest (25 分)
编程题 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...原创 2018-11-01 21:25:52 · 101 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1079 Total Sales of Supply Chain (25 分)
编程题 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. St...原创 2018-11-09 09:48:29 · 116 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1086 Tree Traversals Again (25 分)
编程题 1086 Tree Traversals Again (25 分) An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbe...原创 2018-11-09 09:53:15 · 92 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1090 Highest Price in Supply Chain (25 分)
编程题 1090 Highest 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. ...原创 2018-11-09 10:04:23 · 105 阅读 · 0 评论 -
牛客网[编程题]--彩色的砖块
题目描述 小易有一些彩色的砖块。每种颜色由一个大写字母表示。各个颜色砖块看起来都完全一样。现在有一个给定的字符串s,s中每个字符代表小易的某个砖块的颜色。小易想把他所有的砖块排成一行。如果最多存在一对不同颜色的相邻砖块,那么这行砖块就很漂亮的。请你帮助小易计算有多少种方式将他所有砖块排成漂亮的一行。(如果两种方式所对应的砖块颜色序列是相同的,那么认为这两种方式是一样的。) 例如: s = "AB...原创 2019-02-23 15:10:59 · 270 阅读 · 0 评论