![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
题
谛听-
线上幽灵
展开
-
数组中第 k 大的数字
#include <iostream>using namespace std;int partion(int arr[], int left, int right) { if (left >= right) { return left; } int i = left, j = right; int tmp = arr[i]; while (i < j) { while (i < j &am原创 2021-01-24 16:12:38 · 146 阅读 · 0 评论 -
输出两个字符串数字的差
已知:第一个数字大于第二个数字。#include <iostream>#include <vector>using namespace std;// 1004// 45// 959// 114// 45// 69string subtract(string a, string b) { if (a == "") { return ""; } if (b == "") { return原创 2021-01-19 22:39:07 · 464 阅读 · 1 评论 -
最大矩形
试题名称: 最大的矩形 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi。这n个矩形构成了一个直方图。例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3。 请找出能放在给定直方图里面积最大的矩形,它的边要与坐标轴平行。对于上面给出的例子,最原创 2015-12-08 21:11:38 · 641 阅读 · 0 评论 -
出现次数最多的数
试题名称: 出现次数最多的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。 输入格式 输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻原创 2015-12-08 21:05:03 · 666 阅读 · 0 评论 -
大整数阶乘
#include <iostream>#include <fstream>#include <queue>#include <algorithm>using namespace std;struct BigInteger{ int len; //位数 int nums[100]; //大整数};//将一个数字转换为大整数BigInteger crea原创 2015-12-06 21:56:41 · 570 阅读 · 0 评论 -
生命游戏
100人围成一圈,按顺序排号。从第一个人开始报数,数到3的人退出圆圈,余下的人连接起来,最后留下的是几号?#include <iostream>#include <fstream>#include <queue>#include <algorithm>using namespace std;int main(){ int num[101]; int baoshu = 1;原创 2015-12-06 21:15:35 · 408 阅读 · 0 评论 -
句子逆序
第一种方法:#include < iostream >#include < string >using namespace std;void Reverse(char *pBegin, char *pEnd){ //判断字符串是否长度大于1。 if (pBegin == pEnd) return; //判断交换的条件。 while (pBegin原创 2015-12-07 19:40:50 · 303 阅读 · 0 评论 -
STL_全排列
#include <iostream>#include <algorithm>using namespace std;int main(){ int a[] = {1, 2, 3}; do { for(int i=0; i<3; i++) cout << a[i] << " "; cout << endl;原创 2015-12-07 21:24:59 · 261 阅读 · 0 评论 -
STL_迭代器、map
//来源: 天勤#include <iostream>#include <vector>#include <map>#include <string>using namespace std;int main(){ //迭代器 cout << "迭代器使用示例:\n"; vector<int> v; for(int i=1; i<=10; i++)原创 2015-12-08 10:03:34 · 795 阅读 · 0 评论 -
年历输出
标准输出某年的日历,要求星期和日期对应//转自:http://bbs.csdn.net/topics/390284667#include <stdio.h>#include <math.h>void printmonth(int m);void printhead(int m);int daysofmonth(int m);int firstday(int y);int year,we转载 2015-12-07 20:35:04 · 476 阅读 · 1 评论 -
子集生成
#include <iostream>#include <algorithm>using namespace std;//子集生成//增量构造法void print_subset(int a[], int cur, int n){ for(int i=1; i<cur; i++) cout << a[i] << " "; cout << endl; in原创 2015-12-07 22:03:51 · 245 阅读 · 0 评论 -
c库函数
//来源:天勤计算机考研复试上机指导#include <iostream>#include <cstring>using namespace std;int main(){ //从字符串中取出数字 //sscanf以一个已知的字符串作为输入源 printf("sscanf用法示例:\n"); char time[] = "9:25:12"; int hh原创 2015-12-08 09:39:30 · 244 阅读 · 0 评论 -
星期几
#include <stdio.h>#include <math.h>/*用到了公式:s = floor( (y-1) + (y-1)/4 - (y-1)/100 + (y-1)/400 + c )最后 s%7 即为星期c 为从元旦到这天的天数,y为年份该公式可以计算1582年以后的日期 */int daysofmonth(int m);int compute(int y, int m原创 2015-12-07 20:54:35 · 357 阅读 · 0 评论 -
ISBN号码
问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言,例如0代表英语;第一个分隔符“-”之后的三位数字代表出版社,例如670代表维京出版社;第二个分原创 2015-12-08 21:08:00 · 524 阅读 · 0 评论 -
有趣的数
试题名称: 有趣的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次。 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前。 3. 最高位数字不为0。 因此,符合我们定义的最小的有趣的数是2013。除此以外,4位的有趣的数还原创 2015-12-08 21:01:46 · 454 阅读 · 0 评论 -
Magic Box
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When the circus is performing, Sunny puts some balls into the box one by one. The balls are in three colors: red(R), y原创 2016-01-12 20:52:17 · 510 阅读 · 0 评论 -
Beautiful String
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.)Here are some example of valid beautiful strings原创 2016-03-15 19:10:36 · 370 阅读 · 0 评论 -
String Matching Content Length
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We define the matching contents in the strings of strA and strB as common substrings of the two strings. There are two additional restrictions on the common s原创 2016-03-15 20:46:30 · 440 阅读 · 0 评论 -
Browser Caching
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 When you browse the Internet, browser usually caches some documents to reduce the time cost of fetching them from remote servers. Let’s consider a simplified原创 2016-03-16 16:56:46 · 516 阅读 · 0 评论 -
Hamiltonian Cycle
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a directed graph containing n vertice (numbered from 1 to n) and m edges. Can you tell us how many different Hamiltonian Cycles are there in this graph?原创 2016-03-16 21:29:40 · 479 阅读 · 0 评论 -
Numeric Keypad
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The numberic keypad on your mobile phone looks like below:1 2 3 4 5 6 7 8 9 0 Suppose you are holding your mobile phone with single hand. Your thumb poi原创 2016-02-18 12:43:54 · 374 阅读 · 0 评论 -
Highway
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 In the city, there is a one-way straight highway starts from the northern end, traverses the whole city southward, and finishes at the southern end. Due to so原创 2016-03-17 12:01:52 · 410 阅读 · 0 评论 -
Have Lunch Together
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Everyday Littile Hi and Little Ho meet in the school cafeteria to have lunch together. The cafeteria is often so crowded that two adjacent seats are hard to f原创 2016-03-17 15:11:58 · 451 阅读 · 0 评论 -
Clicker
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Ho is obsessed with a computer game called “Clicker”. In this game player spends coins to raise his heroes’ level and gains more coins by sending his h原创 2016-03-17 20:47:19 · 364 阅读 · 0 评论 -
Lost in the City
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.Fortunately, Little Hi has a map of the city. The map原创 2016-03-17 22:12:38 · 613 阅读 · 0 评论 -
Coordinates
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Give you two integers P and Q. Let all divisors of P be X-coordinates. Let all divisors of Q be Y-coordinates.For example, when P=6 and Q=2, we can get the co原创 2016-03-06 19:33:56 · 615 阅读 · 0 评论 -
HIHO Drinking Game
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a drinking game called HIHO. The game comprises N rounds. Each round, Little Hi pours T milliliter of water into Little Ho原创 2016-03-18 11:48:47 · 368 阅读 · 0 评论 -
Divided Product
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given two positive integers N and M, please divide N into several integers A1, A2, …, Ak (k >= 1), so that:0 < A1 < A2 < … < Ak;A1 + A2 + … + Ak = N;A1, A2原创 2016-03-18 15:32:56 · 304 阅读 · 0 评论 -
Spring Outing
时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outing. N people are voting for a destination out of K candidate places.The voting progress is below:First the class vote原创 2016-02-21 13:56:24 · 594 阅读 · 0 评论 -
leetcode---Two Sum
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.Example: Given nums = [2, 7, 11,原创 2016-04-01 21:12:34 · 262 阅读 · 0 评论 -
leetcode---Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh原创 2016-04-01 22:46:27 · 261 阅读 · 0 评论 -
leetcode---House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour,原创 2016-04-02 12:13:06 · 235 阅读 · 0 评论 -
leetcode---Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector<string>& strs) { int len = strs.size();原创 2016-04-02 16:05:16 · 259 阅读 · 0 评论 -
leetcode---Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321class Solution { public: int reverse(int x) { if(x > pow(2, 31)-1 || x < -1 * pow(2, 31)) //溢出原创 2016-04-02 16:49:23 · 239 阅读 · 0 评论 -
leetcode---String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.N原创 2016-04-02 17:42:07 · 239 阅读 · 0 评论 -
leetcode---Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: bool isPalindrome(int x) { if(x < 0) //负数 return false; int n = x;原创 2016-04-02 18:24:06 · 252 阅读 · 0 评论 -
leetcode---Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListNode原创 2016-04-02 18:49:15 · 219 阅读 · 0 评论 -
leetcode---Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “原创 2016-04-02 18:58:45 · 236 阅读 · 0 评论 -
leetcode---Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list be原创 2016-04-02 19:32:04 · 237 阅读 · 0 评论 -
leetcode---Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution {public: int strStr(string haystack, string needle) {原创 2016-04-02 19:39:06 · 232 阅读 · 0 评论