- 博客(361)
- 资源 (1)
- 收藏
- 关注
原创 LeetCode 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance. Note: 0≤x,y<231.0 ≤ x, y
2017-02-22 22:52:20 348
原创 LeetCode 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: The given integer is guaranteed to fit within the range of a 32-b
2017-02-22 22:49:33 331
原创 LeetCode 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this word
2017-02-21 15:23:56 401
原创 LeetCode 20. 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 "
2017-02-21 11:06:05 270
原创 LeetCode 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive inte
2017-02-20 11:33:41 383
原创 LeetCode 66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are st
2017-02-20 11:31:50 580
原创 LeetCode 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as
2017-02-20 11:30:11 199
原创 LeetCode 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here
2017-02-20 11:28:34 207
原创 LeetCode 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.程序代码:bool isPalindrome(int x) { if(x<0) return false; else if(x<10) return true; else {
2017-02-20 11:27:22 211
原创 LeetCode 8. 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
2017-02-20 11:25:22 230
原创 LeetCode 7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed inte
2017-02-20 11:23:56 225
原创 LeetCode 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the le
2017-02-20 11:22:03 243
原创 LeetCode 2. Add Two Numbers
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 it
2017-02-20 11:20:25 277
原创 LeetCode 1. 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, and you may not use the same e
2017-02-20 11:18:41 268
原创 PAT-B 1056. 组合数的和
PAT-B 1056. 组合数的和给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。输入格式:输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。输出格式:输出所有可能组合出来的2位数字的和。输入样例:3 2 8 5输出样例
2017-01-14 21:58:09 406
原创 PAT-B 1057. 数零壹
PAT-B 1057. 数零壹给定一串长度不超过10510^5的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串“PAT (Basic)”,其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个0、4个1。输入格式:输入在一行中给出长度不
2017-01-14 21:56:26 428
原创 PAT-B 1058. 选择题
PAT-B 1058. 选择题批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。输入格式:输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文
2017-01-14 21:53:31 529
原创 PAT-B 1059. C语言竞赛
PAT-B 1059. C语言竞赛C语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽:冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!其他人将得到巧克力。给定比赛的最终排名以及一系列参赛者的ID,你要给出这些参赛者应该获得的奖品。输入格式:输入第一行给出一个正整数N(<=1
2017-01-14 21:51:08 328
原创 PAT-B 1061. 判断题
PAT-B 1061. 判断题判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。输入格式:输入在第一行给出两个不超过100的正整数N和M,分别是学生人数和判断题数量。第二行给出M个不超过5的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0代表“非”,1代表“是”。随后N行,每行给出一个学生的解答。数字间均以空格分隔。输出格式:按照输入的顺序输出每个学生的
2017-01-14 21:48:46 408
原创 PAT-B 1063. 计算谱半径
PAT-B 1063. 计算谱半径在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界。换言之,对于给定的n个复数空间的特征值{a1+b1i, …, an+bni},它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模。现在给定一些复数空间的特征值,请你计算并输出这些特征值的谱半径。输入格式:输入第一行给出正整数N(<= 10000)是输入的特征值的个数。随后N行,每行给出1个特征值的实部和
2017-01-14 21:47:01 340
原创 PAT-B 1064. 朋友数
PAT-B 1064. 朋友数如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如123和51就是朋友数,因为1+2+3 = 5+1 = 6,而6就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。注意:我们默认一个整数自己是自己的朋友。输入格式:输入第一行给出正整数N。随后一行给出N个正整数,数字间以空格分隔。题目保证所有数字
2017-01-14 21:43:50 505
原创 PAT-B 1065. 单身狗
PAT-B 1065. 单身狗“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。输入格式:输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后
2017-01-14 21:41:20 891
原创 map应用:反片语
map应用:反片语map就是从键(key)到值(value)的映射。因为重载了[]运算符,map像是数组的高级版。例如,我们可以用一个map例题:输入一段文本,找出所有满足条件的单词,需满足的条件是该单词不能通过字母重拍得到文本中的另外一个单词。在判断时,字母不区分大小写,但在输出时应保留输入中的大小写,按照字典序进行排列输出(所有大写字母在所有小写字母的前面) 比如一段文本中出现God和dog,
2016-10-01 22:40:30 399
原创 set应用:提取文本中所有不同的单词
set应用:提取文本中所有不同的单词set是一个常用的容器,是数学意义上的集合–每个元素最多只能出现一次。和sort函数一样,自定义的类型(struct、class)也可以构造set,但是同样必须定义“小于”运算符。 例题: 输入一个文本,找出所有不同的单词,按照字典序从小到大输出。单词不区分大小写,大写的单词按小写输出。这里的单词定义为连续的字母序列。 样例输入:I am a student
2016-10-01 20:46:29 1445
原创 笔试题(四)
笔试题(四)题目 风口的猪-中国牛市 思路分析: 假设第i天买入第二只股票,则总的受益为第0~i-1天的最大受益加上第i天到最后一天的最大受益。int maxsum(int a[],int i,int len);这个函数计算在第i天买入第二只股票的最大受益程序代码:#include<stdio.h>int maxsum(int a[],int i,int len);int price[105
2016-09-12 16:18:20 336
原创 求一个整数的二进制表示中1的个数
求一个整数的二进制表示中1的个数求一个整数的二进制表示中1的个数有一个巧妙的方法,如下:int CountOne(int n){ int count; while(n) { n=n&(n-1); count++; } return count;}
2016-09-12 15:00:38 457
原创 笔试题(三)
笔试题(三)题目1 12进制12进制与十进制的字符对应如下: 十进制0~9分别对应十二进制的0~9; 字符‘A’对应十二进制的10; 字符‘B’对应十二进制的11。 输入一个十进制数,输出其12进制表示。 输入样例 13输出样例11程序代码:#include<stdio.h>#include<string.h>char c[1000];int main(){ int
2016-09-12 14:16:35 700
原创 笔试题(二)
笔试题(二)题目1给定一个正整数n,求满足i+j=n的质数对的个数。比如10,有两组(i,j)满足条件,分别为(3,7)、(5,5)。 样例输入:10样例输出2程序代码:#include<stdio.h>#include<math.h>int isPrime(int n);int main(){ int n; int i=2,j=n-i; int count =
2016-09-12 13:52:50 273
原创 笔试题(一)
笔试题(一)输入一个正整数n(n<=100),按照规定格式打印出来。输出只包含数字、*号和换行符。不允许多余的空格。 样例输入:5样例输出13*24*5*610*9*8*711*12*13*14*15程序代码:#include<stdio.h>void print(int n);int main(){ int n; scanf("%d",&n); print
2016-09-12 13:31:21 321
原创 PAT-A 1088. Rational Arithmetic
1088. Rational ArithmeticFor two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Specification:Each input file
2016-08-14 17:34:18 305
原创 PAT-A 1078. Hashing
1078. HashingThe task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be “H(
2016-08-14 17:28:14 448
原创 PAT-A 1090. Highest Price in Supply Chain
1090. Highest Price in Supply ChainA supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer.Starting from on
2016-08-14 17:20:05 282
原创 PAT-A 1064. Complete Binary Search Tree
1064. Complete Binary Search TreeA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less tha
2016-08-14 10:04:04 352
原创 PAT-A 1009. Product of Polynomials
1009. Product of PolynomialsThis 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 li
2016-08-13 21:06:24 582
原创 PAT-A 1002.A+B for Polynomials
1002. A+B for PolynomialsThis time, you are supposed to find A+B where A and B are two polynomials.InputEach input file contains one test case. Each case occupies 2 lines, and each line contains the in
2016-08-13 20:25:48 357
原创 PAT-A 1004.Counting Leaves
1004. Counting LeavesA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. InputEach input file contains one test case. Each case sta
2016-08-13 18:24:05 486
原创 PAT-A 1094. The Largest Generation
1094. The Largest GenerationA family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the
2016-08-13 17:24:38 313
原创 图的邻接表表示及其BFS遍历
图的邻接表表示及其BFS遍历有下面这张图: 假设该图为有向图,边的指向均为小序号指向大序号。那么对该图的BFS遍历如下(假设从序号0的节点开始遍历): 遍历结果应为:a b f c g i d e hBFS遍历类似于树的层序遍历,需要用到队列。下面是程序代码:1.队列定义和相关操作文件1 queue.h//1.queue.h#ifndef QUEUE_H#define QUEUE
2016-08-09 14:11:23 1996
原创 图的邻接表表示及其DFS遍历
图的邻接表表示及其遍历1.图的结构定义#define MAXVEX 100#define true 1typedef char VertexType; //定义图节点值得类型,可随意更换typedef int EdgeType; typedef struct EdgeNode //定义边表节点{ int adjvex;
2016-08-08 17:34:37 915
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人