![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++ 算法题(基础)
东都大白兔
草原上最美的花
展开
-
C++ stack pop()返回值 error: cannot initialize a variable of type ‘int‘ with an rvalue of type ‘void‘
LeetCode一道链表倒置题目struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {public: vector<int> reversePrint(ListNode* head) { vector<int> ans; stack<int&g.原创 2021-01-15 18:47:03 · 10890 阅读 · 1 评论 -
二分(折半)查找——以 LeetCode 35题为例
来自LeetCode每日一题,最近恰好在复习数据结构,所以整理一下二分查找#include<iostream>#include<vector>using namespace std;class Solution {public: int searchInsert(vector<int>& nums, int target) { int length = nums.size(); int low = 0, hi原创 2020-07-17 22:32:37 · 191 阅读 · 0 评论 -
给学妹写C程——中国海洋大学C语言程序设计课作业(二)
2020年的海大C程序设计(第六章),自己做了一份答案一 求数组的最小值与次小值【问题描述】从键盘输入10个整数成绩到一个数组中,找出数组中的最小数和次小数,并把最小数和a[0]中的数对调、次小数和a[1]中的数对调,其余数据位置不变。【输入形式】屏幕上显示输入成绩的提示信息,用键盘输入一个成绩,接着提示输入下一个,直到结束。【输出形式】先依输入的顺序输出数组初始的10个数,任...原创 2020-04-21 14:42:23 · 2838 阅读 · 0 评论 -
给学妹写C程——中国海洋大学C语言程序设计课作业(一)
2020年的海大C程序设计,自己做了一份答案一 最值求解与数据统计键盘输入一组学生成绩,输入以-1作为输入的结束。统计这批数据的个数,输出有效数据的个数,最大值,最小值,平均值# include<stdio.h>int main(){ int num = 0, max, min, score; float avg, sum = 0; while(tru...原创 2020-04-19 20:09:40 · 5927 阅读 · 26 评论 -
noip200205 均分纸牌 DP动态规划
原题 洛谷:https://www.luogu.org/problemnew/show/P1031从左向右,如果第i个堆的数量不为平均,则i+1堆 = i+1堆 + 第i堆 - 平均亦可将数组置为 卡片数-平均数,若i堆 != 0 , 则 a[i+1] = a[i+1] + a[i]#include<iostream>using namespace std ;int...原创 2019-07-09 18:27:25 · 256 阅读 · 0 评论