c++
咸鱼一只233
Code change life.
展开
-
PAT甲级1007. Maximum Subsequence Sum (25)
一道简单考察动态规划的题目。好了,我们先看题目吧。/*Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the co原创 2017-03-05 12:54:55 · 229 阅读 · 0 评论 -
LeetCode 822 Card Flipping Game
LeetCode 821 Card Flipping Game传送门题目分析 On a table are N cards, with a positive integer printed on the front and back of each card (possibly different). We flip any number of cards, and ...原创 2018-04-23 20:28:53 · 830 阅读 · 0 评论 -
PAT甲级1002 A + B
PAT甲级1002这个问题讲的就是多项式加起来,根据题意设置一个数组把系数存储起来就好了,最后输出。 Talk is cheap, show me the code.//包含头文件#include <iostream>#include <cstdio>//需要保留小数点后一位,可以用%.1f,暂时还不会c++的标准输出#define MAXK 1001 //在数组中使用using names原创 2017-02-19 11:13:25 · 259 阅读 · 0 评论 -
LeetCode 829. Consecutive Numbers Sum
LeetCode 829 Consecutive Numbers Sum传送门题目分析 Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? Example 1: Input: 5Output: 2Expla...原创 2018-05-11 21:06:45 · 2281 阅读 · 0 评论 -
PAT 1016. Phone Bills (25)
PAT 1016. Phone Bills (25)题目分析原题相信大家都看见了,题目几乎不涉及算法,主要就是考大家的细心,题目大意就是给我们所有用户的长途电话记录,根据用户分组,计算每个用户需要交的电话费,打印账单,这个题隐含着如果一个用户没有一次完整的打电话记录就不输出,我起初在这个上面栽了跟头,后来及时更正了。解题逻辑读入花费的收费信息读入用户的信息,使用map将...原创 2018-05-08 19:12:41 · 184 阅读 · 0 评论 -
LeetCode 842 Split Array into Fibonacci Sequence
LeetCode 842 Split Array into Fibonacci Sequence传送门题目分析 Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like sequence [123, 456, 579]. Formally, a Fi...原创 2018-05-27 23:44:22 · 1448 阅读 · 0 评论 -
LeetCode 838 Push Dominoes
LeetCode 838 Push Dominoes传送门题目分析 There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to th...原创 2018-05-24 11:27:31 · 1278 阅读 · 0 评论 -
LeetCode 859 Buddy Strings
LeetCode 859 Buddy Strings传送门题目分析 Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: I...原创 2018-06-24 18:48:24 · 1555 阅读 · 0 评论 -
LeetCode 859 Score of Parentheses
LeetCode 859 Score of Parentheses传送门题目分析 Given a balanced parentheses string S, compute the score of the string based on the following rule: () has score 1 AB has score A + B, wher...原创 2018-06-24 18:56:47 · 1158 阅读 · 0 评论 -
LeetCode 858 Mirror Reflection
LeetCode 858 Mirror Reflection传送门题目分析 There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining co...原创 2018-06-24 19:58:21 · 1110 阅读 · 0 评论 -
LeetCode 853. Car Fleet
LeetCode 853. Car Fleet传送门题目分析 N cars are going to the same destination along a one lane road. The destination is target miles away. Each car i has a constant speed speed[i] (in miles ...原创 2018-06-17 16:49:24 · 1385 阅读 · 0 评论 -
LeetCode 821 Shortest Distance to a Character
LeetCode 821 Shortest Distance to a Character传送门题目分析 Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. ...原创 2018-04-23 20:06:38 · 291 阅读 · 0 评论 -
LeetCode 807 Max Increase to Keep City Skyline
LeetCode 807 Max Increase to Keep City Skyline传送门题目分析 In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the h...原创 2018-03-25 22:30:48 · 808 阅读 · 0 评论 -
PAT甲级1005. Spell It Right
b( ̄▽ ̄)d ,水题一道,没有难度。看原题:Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains原创 2017-03-09 20:54:38 · 216 阅读 · 0 评论 -
PAT甲级1008. Elevator (20)
求电梯运行的总时间简单不解释题目在这里 The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified原创 2017-03-09 21:03:38 · 180 阅读 · 0 评论 -
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原创 2017-03-09 21:19:15 · 231 阅读 · 0 评论 -
PAT甲级1004CountingLeaves
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contains one test case. Each case starts with a line原创 2017-04-24 12:49:38 · 226 阅读 · 0 评论 -
PAT甲级1006. Sign In and Sign Out (25)
闲来无事刷道题吧。PAT1006,题目先贴上来 /*At the beginning of every day, the first person who signs in the computer room will unlock the door,and the last one who signs out will lock the door. Given the records of原创 2017-03-05 10:14:04 · 217 阅读 · 0 评论 -
c++常量方法相关内容(转载)
本文总结了静态成员的使用、单例的实现、常量对象与常量方法,以及如何将常量方法重载为普通方法。静态成员对象成员的声明前加 static 即可定义为静态成员,静态成员必须在声明类的文件中进行声明(通常会初始化),否则链接错。 访问静态成员可以通过类名,也可以通过对象名。class CPerson{ static int count;};int CPerson::count = 0;CPers转载 2017-06-29 22:54:00 · 299 阅读 · 0 评论 -
c++string与数字的互转
c++string与数字的互转c++reference上面列举了一些方法。1.数字转string:数字转string,标准库里专门提供了函数: 包含的头文件 string,使用的话就是直接std::to_string(T para),会返回一个string,这个函数接受的参数可以是int、long、long long、及其unsigned,float、double、long d...原创 2017-08-13 09:44:50 · 2473 阅读 · 0 评论 -
Huffman树的实现
最近复习的时候遇见了哈夫曼编码,虽然在数据结构和离散数学课上都见识到了这个编码树,不过今天时第一次动手写哈夫曼树,借助了c++的stl写起来还是比较简单的。话不多说,现在开始。1. 统计字符频率统计字符这个还是很简单的,首先我们要打开要处理的文件, // 输入的文件名 std::string file_name; std::cout << "Pleas...原创 2017-12-09 16:47:03 · 210 阅读 · 0 评论 -
Leetcode 318 Maximum Product of Word Lengths
Leetcode 318 Maximum Product of Word Lengths题目分析 Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You ma...原创 2018-03-10 10:36:23 · 291 阅读 · 0 评论 -
LeetCode 796 Rotate String
LeetCode 796 Rotate String传送门:LeetCode 796题目分析题目原文: We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost character to the rightmost posi...原创 2018-03-11 15:50:59 · 259 阅读 · 0 评论 -
LeetCode 804 Unique Morse Code Words
LeetCode 804 Unique Morse Code Words传送门题目分析 International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "...原创 2018-03-25 22:22:55 · 860 阅读 · 0 评论 -
LeetCode 855. Exam Room
LeetCode 855. Exam Room传送门题目分析 In an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1. When a student enters the room, they must sit in the seat that maximizes t...原创 2018-06-17 17:13:43 · 2740 阅读 · 0 评论