
C++
mooe1011
这个作者很懒,什么都没留下…
展开
-
c++ 简单实现bit-map
这里主要写代码,具体原理可以查看https://blog.youkuaiyun.com/weixin_40449300/article/details/87620692假设我们有a数组,里面存放1, 7, 9, 10, 30, 31, 32, 128, 129 这9个数字。由于这9个数字最大为129,我们可以用b[5](129/32=4,4+1=5)数组来表示这9个数字。赋值a[i] & 31表示a[i]%32,对其求余;a[i] >> 5 表示a[i] /32 int...原创 2020-05-19 20:55:17 · 306 阅读 · 0 评论 -
使用C++ map 或者 sort 把几个正整数组合成最小整数或最大整数
连续输入正整数,比如12 34 2 21,把他们整合成一个最小正整数,即1221234注意到map是按字典排序,但有一种情况321,32,字典排序默认长的在后面,正确情况应该是组合成32132.我们可以考虑在读入的时候加入一个字母即可,输出记得去掉字母#include<bits/stdc++.h>using namespace std;int main() { //...原创 2019-03-27 09:19:43 · 593 阅读 · 0 评论 -
网易2018 迷路的牛牛
牛牛去犇犇老师家补课,出门的时候面向北方,但是现在他迷路了。虽然他手里有一张地图,但是他需要知道自己面向哪个方向,请你帮帮他。输入描述:每个输入包含一个测试用例。每个测试用例的第一行包含一个正整数,表示转方向的次数N(N<=1000)。接下来的一行包含一个长度为N的字符串,由L和R组成,L表示向左转,R表示向右转。输出描述:输出牛牛最后面向的方向,N表示北,S表示南...原创 2019-03-31 10:46:24 · 157 阅读 · 0 评论 -
base+ball=games
每个字母为0~9,使得式子成立写了烂代码,过了,期待以后的改进//#include<bits/stdc++.h>using namespace std;int main() { //int b = 0, a = 0, s = 0, e = 0, l = 0, g = 0, m = 0; //freopen("input.txt", "r", stdin); ...原创 2019-03-31 16:58:13 · 1380 阅读 · 0 评论 -
LeetCode 26. Remove Duplicates from Sorted Array C++
Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bymodifyi...原创 2019-03-28 22:18:39 · 121 阅读 · 0 评论 -
必会的快速排序
1.快速排序#include<bits/stdc++.h>using namespace std;//严蔚敏版void printarr(int arr[], int sz) { for (int i = 0; i < sz; i++) { cout << arr[i] << " "; } cout << endl;...原创 2019-04-12 10:17:43 · 130 阅读 · 0 评论 -
网易2020 实习 笔试 外星人阅读
这篇算是亡羊补牢吧,当时没A。已经修改好,不保证正确。题目大意是,人类阅读是从左到右阅读,外星人则是从右到左阅读。输入人类阅读方式的文章,输出外星人阅读方式的文章。例子(全文记不住了,随便写的):输入:700-MA's mother's I'm your HK.??*-/++A's"dasd"sfdfs??输出:??sfdfs"dasd"s'A++/-*?? .HK your m'I...原创 2019-04-03 09:57:25 · 451 阅读 · 0 评论 -
LeetCode 204. Count Primes C++ 素数筛
Count the number of prime numbers less than a non-negative number,n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.trick:我们判断100是否为素数时,在...原创 2019-04-17 16:24:47 · 122 阅读 · 0 评论 -
LeetCode 1029. Two City Scheduling C++ 比较器 另加Python
There are2Npeople a company is planning to interview. The cost of flying thei-th person to cityAiscosts[i][0], and the cost of flying thei-th person to cityBiscosts[i][1].Return the ...原创 2019-05-16 16:39:11 · 382 阅读 · 0 评论 -
LeetCode 56. Merge Intervals C++ 比较器 与 Python 两种语言
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...原创 2019-05-30 21:15:48 · 198 阅读 · 0 评论 -
LeetCode 299. Bulls and Cows C++ & python zip
You are playing the followingBulls and Cowsgame with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha...原创 2019-06-03 16:12:52 · 362 阅读 · 0 评论 -
网易2019秋季招聘 丰收 二分法 C++
链接:https://www.nowcoder.com/questionTerminal/83b419c027fa490aa60669b0e7dc06a3在果园里有N堆苹果,每堆苹果的数量为ai,小易希望知道从左往右数第x个苹果是属于哪一堆的。牛牛觉得这个问题太简单,所以希望你来替他回答。输入描述:第一行一个数n(1 <= n <= 105)。第二行n个数ai(1 &l...原创 2019-03-21 23:31:57 · 156 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray C++
Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...原创 2019-03-18 12:34:27 · 138 阅读 · 0 评论 -
LeetCode 15. 3Sum C++
Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not conta...原创 2019-03-17 23:12:55 · 197 阅读 · 0 评论 -
剑指offer 66题 二维数组中的查找
题目描述在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。class Solution {public: bool Find(int target, vector<vector<int> > array) { ...原创 2019-02-23 21:26:57 · 127 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers C++
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-11-04 19:19:35 · 220 阅读 · 0 评论 -
LeetCode 1. Two Sum C++
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ...原创 2018-11-04 17:01:23 · 128 阅读 · 0 评论 -
剑指offer 66题 替换空格
题目描述请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。先统计空格个数,然后扩展字符串长度,从后面插入class Solution {public: void replaceSpace(char *str,int length) { int size=str...原创 2019-03-05 17:43:56 · 104 阅读 · 0 评论 -
LeetCode 3. Longest Substring Without Repeating Characters C++
Given a string, find the length of thelongest substringwithout repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:...原创 2019-03-06 11:31:56 · 166 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays C++
There are two sorted arraysnums1andnums2of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assumenums1andn...原创 2019-03-07 10:54:55 · 143 阅读 · 0 评论 -
C++ primer 学习笔记 第三章 字符串、向量和数组
C++ primer 第5版第三章关键词:string、vector、迭代器、数组上一篇 第二章 指针和引用——https://blog.youkuaiyun.com/mooe1011/article/details/878947523.2.1 string对象p76读取读取一行empty和size函数使用上述函数返回的是size_typ...原创 2019-03-14 17:10:33 · 190 阅读 · 0 评论 -
华为 2016 简单错误记录 map按value倒序排列及其应用
简单错误记录开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。处理:1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)3.输入的文件可能带路...原创 2019-03-20 10:12:16 · 161 阅读 · 0 评论 -
LeetCode 11. Container With Most Water C++
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two...原创 2019-03-16 11:32:12 · 115 阅读 · 0 评论 -
LeetCode 7. Reverse Integer C++
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dea...原创 2019-03-12 16:58:15 · 130 阅读 · 0 评论 -
网易2019秋季招聘 俄罗斯方块
荧幕上一共有 n 列,每次都会有一个 1 x 1 的方块随机落下,在同一列中,后落下的方块会叠在先前的方块之上,当一整行方块都被占满时,这一行会被消去,并得到1分。有一天,小易又开了一局游戏,当玩到第 m 个方块落下时他觉得太无聊就关掉了,小易希望你告诉他这局游戏他获得的分数。输入描述:第一行两个数 n, m第二行 m 个数,c1, c2, ... , cm , ci 表示第 i 个...原创 2019-03-21 11:23:55 · 249 阅读 · 0 评论 -
C++ primer 学习笔记 第二章 指针和引用
C++ primer 第5版第二章关键词:指针、引用、绑定、知道**p,*&p区别(指向指针的指针/指向指针的引用)、const、const指针、using、typedef、auto、decltype下一章字符串、向量和数组——https://blog.youkuaiyun.com/mooe1011/article/details/885566652.2 引用p45左值...原创 2019-02-23 17:23:26 · 164 阅读 · 0 评论