自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(26)
  • 收藏
  • 关注

原创 PAT 1077 Kuchiguse (20 分)

1077 Kuchiguse (20 分)The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a...

2018-10-28 14:56:44 178

原创 PAT 1035 Password (20 分)

1035 Password (20 分)To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distingui...

2018-10-28 10:32:34 114

原创 PAT 1073 Scientific Notation (20 分)

1073 Scientific Notation (20 分)Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+−][1−9].[0−9]+E[+−]...

2018-10-27 14:45:50 125

原创 PAT 1061 Dating (20 分)

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 th...

2018-10-27 11:43:58 179

原创 PAT 1058 A+B in Hogwarts (20 分)

1058 A+B in Hogwarts (20 分)If you are a fan of Harry Potter, you would know the world of magic has its own currency system – as Hagrid explained it to Harry, “Seventeen silver Sickles to a Galleon an...

2018-10-26 08:47:16 137

原创 LeetCode 415. Add Strings

415. Add Strings和Add binary一模一样啊。class Solution {public: string addStrings(string num1, string num2) { string result; int N1 = num1.size(),N2 =num2.size(),carry=0; for(i...

2018-10-25 17:43:22 72

原创 PAT 1027 Colors in Mars (20 分)

1027 Colors in Mars (20 分)People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits ar...

2018-10-25 17:07:42 102

原创 LeetCode 67. Add Binary

67. Add Binary这题只能迭代字符串。一个接一个地加。如果想用先把字符串转换为数字。相加后转换为字符串,是不可行的。因为测试数据会给出很长的字符串,是无法转换成数字的。Code:class Solution {public: string addBinary(string a, string b) { int carry=0,N1=a.size(),N...

2018-10-25 16:45:58 122

原创 LeetCode 859. Buddy Strings

859. Buddy StringsBuddy String是指两个字符串:其中一个字符串只用交换两个字符,就能和另一个字符串相等。首先:两个字符串长度要一样,才可能是Buddy Strings.第二:要区分两个字符串是否相等:相等:可以通过交换一个字符串中两个相等的字符比如 ‘aa’ 和‘aa’(LeetCode的example也给出了这个例子)。这个时候我用set统计字符串中Uni...

2018-10-22 11:22:57 228

原创 LeetCode 125. Valid Palindrome

125. Valid Palindrome第一份我写的(垃圾不用看)。第二份大神写的:建议看看class Solution {public: bool isPalindrome(string s) { string change; for(auto x:s) if(isalnum(x)){ if(...

2018-10-21 21:13:59 85

原创 PAT1019 General Palindromic Number (20 分)

1019 General Palindromic Number (20 分)A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All singl...

2018-10-21 19:46:05 131

原创 LeetCode 893. Groups of Special-Equivalent Strings

893. Groups of Special-Equivalent Stringsclass Solution {public: int numSpecialEquivGroups(vector<string>& A) { set<vector<int>> Set; for(auto x:A){

2018-10-21 17:27:20 204

原创 PAT1031 Hello World for U (20 分)

1031 Hello World for U (20 分)Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:h de ll rlowoThat is, ...

2018-10-21 15:52:43 199

原创 PAT1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分)This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each ...

2018-10-21 09:45:14 178

原创 LeetCode344. Reverse String

344. Reverse Stringclass Solution {public: string reverseString(string s) { reverse(s.begin(),s.end()); return s; }};

2018-10-20 09:55:53 103

原创 LeetCode 557. Reverse Words in a String III

557. Reverse Words in a String III这题是反转字符串中的单词。关键是找到单词与单词之间的空格。在题目的Note里:有写单词与单词之间的空格只有一个。所以我的代码每次在找到空格后,只跳过一个。(这题通俗应该写一个循环,把空格都跳过去)。Note: In the string, each word is separated by single space and t...

2018-10-20 00:05:50 74

原创 LeetCode 657. Robot Return to Origin

657. Robot Return to Origin挺简单的模拟题。只要U和D,L和R的出现次数是一样的。Robot就还在原点。Code:class Solution {public: bool judgeCircle(string moves) { int U=0,D=0,L=0,R=0; for(auto x:moves){ ...

2018-10-19 15:12:20 217

原创 PAT 1065 A+B and C (64bit) (20 分)

1065 A+B and C (64bit) (20 分)Given three integers A, B and C in [−263−2^{63}−263, 2632^{63}263], you are supposed to tell whether A+B>C.Input Specification:The first line of the input gives the ...

2018-10-18 23:52:03 305

原创 PAT 1046 Shortest Distance (20 分)

1046 Shortest Distance (20 分)The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specific...

2018-10-18 17:22:17 558

原创 LeetCode 804. Unique Morse Code Words

804. Unique Morse Code Words这应该属于考简单hash。毕竟Morse Code也算是hash函数。迭代vector<string>。 把string -> Morse Code。用set除重。class Solution {public: int uniqueMorseRepresentations(vector<string&gt...

2018-10-18 16:12:04 86

原创 PAT 1042 Shuffling Machine (20 分)

1042 Shuffling Machine (20 分)Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where empl...

2018-10-18 15:58:33 153

原创 LeetCode 709. To Lower Case

LeetCode 709. To Lower Case这题把字符串里所有大写字母改为小写字母。很多语言都自带这个函数(方法).C++里我使用了transform函数。class Solution {public: string toLowerCase(string str) { transform(str.begin(),str.end(),str.begin()...

2018-10-17 09:03:12 124

原创 d-heap

child(i,j) = d*(i-1)+2+jparent(i) = (i-2+d)/d

2018-10-11 11:40:31 1702

原创 LeetCode 703. Kth Largest Element in a Stream

解题思路这个解题思路是我从数据结构与算法分析:C语言描述中看到的。在讲优先队列的时候,这本书提及了优先队列的应用。其中一个应用就是寻找第K大的数。具体思路是:用堆维持一个k个最大元素的集合S(max堆)。当读入下一个数时:如果读入的数字比堆顶元素大舍弃。如果比堆顶元素小:则把堆顶元素删除,并把读入的元素加入堆。在这题中:要求的是从大到小的第K个数。这里我用了STL中的priority_q...

2018-10-11 10:58:50 194 1

原创 重载operator new/delete/new[]/delete[]

Abstact之前看侯捷老师的C++面向对象开发上。老师讲了一个知识点,如下图:在他的C++面向对象高级编程(下)课程中,侯捷老师讲了重载operator new,operator delete。这篇blog主要实现重载operator new/delete。并进行验证上图。Let`s goCode:下面是相应的代码。重载了operator new/delete/new[]/delet...

2018-10-06 12:25:45 2437 2

原创 Tree : Top View

Abstract做了一道题Tree : Top View。下面是解题报告。Top View什么是Top View呢?在二叉树的父节点,从下看:你能看到的结点的集合即是Top View。如下图:结点7和13被8挡住了,所以看不到。只能看到 结点4,8,16,20。怎么确定结点是否被挡在了呢?如上图的po。我是这样定义的:对与一个结点来说:它的左结点位置为该节点位置减一,右结点的位置为该...

2018-10-03 21:24:58 712

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除