
随笔
a819721810
这个作者很懒,什么都没留下…
展开
-
用java写一个万年历
import java.util.Scanner;public class rili { static boolean mark=true; public static void main(String[] args){ Scanner in=new Scanner(System.in); Scanner in1=new Scanner(System原创 2015-04-27 07:30:15 · 7621 阅读 · 1 评论 -
其他进制转十进制(C++)
#include<iostream>#include<math.h>using namespace std;int main(){ int n; cin>>n; int m;//进制数 cin>>m; double sum=0.0; int k=0; while (n!=0) { int a=n%10;原创 2015-06-06 20:41:16 · 1110 阅读 · 0 评论 -
智力题(阿里巴巴校招)
500张骨牌整齐地排成一行,按顺序编号为1、2、3、……、499、500。第一次拿走所有奇数位置上的骨牌,第二次再从剩余骨牌中拿走奇数位置上的骨牌,以此类推。请问最后剩下的一张骨牌的编号是? A.128 B.250 C.256 D.500答案是C 第一次后剩下250个偶数:2,4,6,8……498,500(2的倍数留下,2的一次方) 第二次后剩下125个偶数:4,8,12,16……496原创 2015-07-09 02:19:19 · 3030 阅读 · 0 评论 -
指针数组的应用
问题描述 在主函数中输入10个长度不超过10的字符串,用另一个函数对它们排序,然后在主函数输出这10个已排好序的字符串。要求用指针数组来处理#include<stdio.h>#include<string>#include<iostream>using namespace std;void sort(char *p[],int n){ int i,j,k; char temp原创 2015-06-11 19:02:47 · 661 阅读 · 0 评论 -
static的用法(C)
#include<stdio.h>#include<iostream>using namespace std;static int a=1;void fun1(void){ a=2;}void fun2(void){ int a=3;}void fun3(void){ static int a=4;}int main(int arg){ cout<<原创 2015-06-13 17:37:52 · 444 阅读 · 0 评论 -
分遗产
题目描述有一位阿拉伯老人,生前养有11匹马,他去世前立下遗嘱:大儿子、二儿子、小儿子分别继承遗产的1/2、1/4、1/6。 儿子们想来想去没法分:他们所得到的都不是整数,即分别为11/2、11/4、11/6,总不能把一匹马割成几块来分吧? 聪明的邻居牵来了自己的一匹马,对他们说:“你们看,现在有12匹马了,老大得12匹的1/2就是6匹,老二得12匹的1/4就是3匹, 老三得12匹的1/6就是2匹原创 2015-07-12 14:17:32 · 1269 阅读 · 0 评论 -
用C++实现最小公倍数和最大公约数
#include<iostream>using namespace std;int main(void){ int x, y, num1, num2, temp; printf("请输入两个正整数:\n"); scanf("%d %d", &num1, &num2); if(num1 < num2)//交换 { num1^=num2;原创 2015-07-11 18:46:12 · 5670 阅读 · 0 评论 -
C++类中的const和static
C++类中的const和static 一、const成员变量: const成员变量只是在某个对象的生存期内是常量,而对于整个类而言是可变的。一个类可以创建多个对象,每个对象的const成员变量的值是可以不同的。 因此不能在类声明中初始化const成员变量(普通的const变量必须在定义的时候初始化)。const成员变量的初始化工作必须在构造函数初始化列表中进行。二、static成员变量:stat转载 2015-08-23 16:14:49 · 426 阅读 · 0 评论 -
结构体内存对齐详解
.在32位机器上 设有以下说明和定义: 1234567891011 typedef union { long i; int k[5]; char c; } DATE; struct data { int cat; DATE cow; double dog; } too; DATE max; 则语句 printf(“%d”,size原创 2015-07-31 00:06:16 · 655 阅读 · 0 评论 -
用++操作符完成其它操作符的转换
在只容许使用++操作符的情况下,请完成下面代码,实现减法、乘法和除法。注意:假设操作数全为正整数,并且可以不考虑性能,不能使用–,*,/等操作符。 a). 乘法: int multi(int opl,int op2){//op1*op2} b). 减法: intsub(int op1,int op2){//op1-op2} c). 除法: int div(int op1,int op2)原创 2015-05-18 06:43:57 · 1007 阅读 · 1 评论 -
从尾到头打印链表
题目描述输入一个链表,从尾到头打印链表每个节点的值。返回新链表的头结点。/*** struct ListNode {* int val;* struct ListNode *next;* ListNode(int x) :* val(x), next(NULL) {* }* };*/ class Solu原创 2015-05-07 21:25:15 · 619 阅读 · 0 评论 -
笨小猴
笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼。但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小猴就认为这是个Lucky Word,这样的单词很可能就是正确的答案。 输入 Input 只有一行原创 2015-05-10 11:05:22 · 1749 阅读 · 0 评论 -
查找数组里面的数
有一个int型数组,每两个相邻的数之间的差值不是1就是-1.现在给定一个数,要求查找这个数在数组中的位置。 其实思想就是跳跃查找,因为你知道了一个数,那么它第二个数最多相差1,第三个数最多相差2,而可以用目标数减去这个数来排除一些多余的查找,比如你要的数是10,第一个数是2,那么它前7个数无论如何都达不到10,只有在第8个数才有可能,所以可以直接判断第8个数。 下面是别人的代码借用一下思想大概就原创 2015-05-12 01:34:58 · 970 阅读 · 0 评论 -
single-number
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra原创 2015-05-13 19:22:45 · 484 阅读 · 0 评论 -
same-tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Definition原创 2015-05-13 19:45:19 · 562 阅读 · 0 评论 -
maximum-depth-of-binary-tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree * stru原创 2015-05-13 19:32:36 · 761 阅读 · 0 评论 -
十进制转化为其他进制(C语言)
#include<stdio.h>int a[1000];int k=0;void change(int x,int r){ while (x) { a[k++]=x%r; x=x/r; }}int main(){ int x,r,i; printf("输入一个十进制数:\n"); scanf("%d",&原创 2015-05-14 11:05:15 · 3596 阅读 · 0 评论 -
亲密数
#include <stdio.h> #include <stdlib.h> int qingmiaoduishu(int n){ int i,sum; sum=1;for(i=2;i<=n/2;i++) if (n%i==0) sum+=i; return sum;}void main(){ int a,b,c; for (a=原创 2015-05-14 11:20:02 · 798 阅读 · 1 评论 -
笔试面试排序算法大总结(干货)
排序方法 平均情况 最好情况 最坏情况 辅助空间 稳定性 冒泡排序 O(n^2) O(n) O(n^2) O(1) 稳定 选择排序 O(n^2) O(n^2)原创 2015-09-19 23:14:17 · 588 阅读 · 0 评论