自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(111)
  • 收藏
  • 关注

原创 找出最长的连续数字串

只要找到最长数字串的起始位置,还有长度,就OK了#include #includeusing namespace std; void main(){ string s; cin >> s; int len = s.size(), j = 0,l=0,max=0,k=0; for (int i = 0; i < len; i++){ if (s[i] >= '0'&&s[

2015-09-09 10:10:33 480

原创 海滩上原有多少个桃子(2016)

整体策略,设桃子总数为x,由于m只猴子都是吃掉一个桃子后,余下的可以平方m份,设在总数中加入m-1个桃子,则每只猴子所占的总数不变,包括吃掉的那个(m-1放入后一层总数中),使得每次分成m份时恰好是整分,x的最小值是m的m次方-(m+1)#include //#include using namespace std; void main(){ int m; cin >> m;

2015-09-08 11:00:18 819

原创 最高分是多少(2016)

题目描述:老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩. 输入描述: 输入包括多组测试数据。 每组输入第一行是两个正整数N和M(0 学生ID编号从1编到N。 第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩 接下来又M行,每一行有一个字符C(只取‘Q’或‘U’),和两个正

2015-09-06 10:57:50 826

原创 最大连续的bit数(二进制1的个数)

点击打开链接#include #include using namespace std;int max1(int n){ //unsigned int flag = 1; int count = 0; int max = 0; if (n255) return 0; while (n!=0){ while ((n &1) == 1 && n != 0){ //位运

2015-08-30 10:44:07 650

原创 将真分数分解为埃及分数

点击打开链接若真分数的分子a能整除分母b,则真分数经过化简就可以得到埃及分数,若真分数的分子不能整除分母,则可以从原来的分数中分解出一个分母为b/a+1的埃及分数。用这种方法将剩余部分反复分解,最后可得到结果。#include #include #includeusing namespace std;void main(){ int a, b, c; scanf_s("%l

2015-08-29 11:34:09 565

原创 按照与字母v的距离排序,距离小的在前面。(华为2016)

#include #include using namespace std;struct elem{ int c; int juli;};void main(){ elem a[256]; for (int i = 0; i < 256; i++){ a[i].c = i; a[i].juli = -1; } char input[256]; gets_s(in

2015-08-27 10:57:50 429

原创 DNA序列

找出字符串中G和C,字符个数最多的长度固定的子串  注释:求子串用M.substr(i,j)   从i开始长度为j的子串点击打开链接#include #include using namespace std;int main(){ string dna,temp; int count = 0,max = 0,n; cin >> dna>>n; if

2015-08-25 20:54:41 452

原创 输入整数二进制1的个数(剑指)

注意正数与负数都必须能判断思路:把一个整数减去1,再和原整数做与运算,会把该整数最右边的一个1变成0;#include #include using namespace std;int numberof1(int n){ int count = 0; while (n){ count++; n = n&(n - 1); } return count;}void

2015-08-25 19:49:06 299

原创 放苹果(递归)

点击打开链接m个苹果放入n个盘子有几种方法。用递归,n个盘子有一个为空,或者n个盘子都至少有一个。#include #include using namespace std;int sharingapple(int m, int n){ if (m == 1 || n == 1)//只有一个苹果或者只有一个盆子,则只有一种放法。 return 1; else if (

2015-08-25 11:18:21 951

原创 蛇形矩阵

点击打开链接#include #include using namespace std;void main(){ int n; cin >> n; int a[100][100]; a[0][0] = 1; for (int i = 0; i < n; i++){ if (i!=0) a[i][0] = a[0][i - 1] + 1; for (int

2015-08-24 10:58:41 320

原创 站点访问量太对的解决办法(阿里2015)

A公司打算搭建一个Android App下载的Web站点,计划将目前常见的手机APP都放到这个网站上提供下载。因为业务开展初期下载量很小,技术部门就用了1台服务器,给服务器配置了一个公网IP对外进行服务。随着销售部门的推广到位,用户量和下载量呈指数级上载,要求技术部门马上进行改造。如果你是技术部门经理,你会怎么改造这个站点,以满足高负载的需求。提示:短时间修改网站的代码不现实,其他方面的各种改

2015-08-22 16:47:32 309

原创 选村长(360笔试)

360员工桂最近申请了一个长假,一个人背着包出去自助游了。  路上,他经过了一个小镇,发现小镇的人们都围在一棵树下争吵。桂上前询问情况,得知小镇的人们正缺一个镇长,他们希望能选一个知名又公正的镇长,即,大家希望能选出一个人,所有人都认识他,但同时他不认识镇上除自己以外的其他人(在此,我们默认每个人自己认识自己)。可是小镇里的人太多了,一下子大家谁也说服不了谁。  “这简单啊。”桂表示。于是

2015-08-22 14:51:42 848

原创 输出能被其它元素整除的数(2016)

描述输入一组大于0小于1000的整数,且均不相同,逗号隔开,输出其中能被这些整数中其他元素整除的那些元素。输入输出格式要求输入要求同上述描述,输出要求整数顺序按照输入时的顺序输出。样例输入:2,4,6,8,10,12,3,9 输出:4,6,8,10,12,9每个元素分别对所有元素求余,能整除的就count加1,输出count大于2的,注意最后一个不能输出逗号

2015-08-22 09:02:46 1601

原创 二叉树差值最大(阿里2015)

写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵二叉树中相差最大的两个节点间的差值绝对值。请注意程序效率。//递归求最大值,最小值,时间复杂度o(n)void findminmax(treenode* tree, int& maxval, int& minval){ if (maxval val) maxval = tree->val; if (min

2015-08-21 15:28:08 703

原创 指定分隔符,输出指定的段(2016)

题目一:根据指定的分隔符分隔字符串,并输出指定的段描述根据指定的分隔符分隔字符串,并输出指定的段。如果指定的段超过分隔的段数,输出:NULL举例: AAA?BBB?CCC??2 字符串为:AAA?BBB?CCC? 分隔符为:? 指定的段为:2 字符串分割为:AAA BBB CCC共三段,第2段字符串为:BBB输入输出格式要求输入分隔字符串长度小于128个字符

2015-08-20 10:33:44 1442 1

原创 最长公共子串的长度(阿里)

给定一个 query 和一个 text,均由小写字母组成。要求在 text 中找出以同样的顺序连 续出现在 query 中的最长连续字母序列的长度。例如, query 为“acbac”,text 为 “acaccbabb”,那么 text 中的“cba”为最长的连续出现在 query 中的字母序列,因此, 返回结果应该为其长度 3。请注意程序效率。#include #includeusin

2015-08-19 21:09:43 561

原创 排序(sort函数的使用)

点击打开链接#include #include#include //sort需要包含的库函数using namespace std;bool compare1(int &a, int &b){ //降序排序 return a > b;}bool compare2(int &a, int &b){ //升序排序 return a < b;}void sortarray(i

2015-08-19 10:57:49 480

原创 字符统计

点击打开链接#include #include//#includeusing namespace std;struct Elem{ int c; int count;};void main(){ Elem a[256]; char input[256]; for (int i = 0; i < 256; i++){ a[i].c = i; a[i].count =

2015-08-19 10:50:05 278

原创 输入字符数不确定的数组

#include #includeusing namespace std;void main(){ int i = 1, a[100]; cin >> a[0]; while (getchar()!='\n'){ cin >> a[i++]; } cout << "输入的数组为:" << endl; for (int j = 0; j < i; j++){ co

2015-08-18 10:25:00 702

原创 字符逆序

点击打开链接#include #includeusing namespace std;string change(string s){ int len= s.length(); char t; for (int i = 0, j = len - 1; i < j; i++, j--){ t = s[i]; s[i] = s[j]; s[j] = t; } retur

2015-08-17 11:23:29 308

原创 求解立方根

点击打开链接#include #include#includeusing namespace std;double getcuberoot(double input){ double i = 1.0; int flag = 0; while (i < input){ if (i*i*i == input){ return i; } else i

2015-08-17 10:54:42 378

原创 最小公倍数

点击打开链接#include #includeusing namespace std;void main(){ int a, b,t=1; cin >> a >> b; int s = a*b; int n = a < b ? a : b; for (int i = n; i >=1; i--){//t为a,b的最大公约数。 if (a%i == 0 && b%i ==

2015-08-17 10:02:15 235

原创 质数因子

点击打开链接#include #includeusing namespace std;bool isprime(long num){ for (long i = 2; i < num; i++){ if (num%i == 0) return false; break; } return true;}void getResult(long &num){ in

2015-08-15 13:53:52 283

原创 合并表记录

点击打开链接#include #includeusing namespace std;struct Record{ int Index; int Value;};void main(){ int n,t1,t2; cin >> n; cout << "强输入" << n << "个键值对:" << endl; struct Record array[100]; for

2015-08-15 10:12:29 280

原创 取近似值

点击打开链接#include #includeusing namespace std;void main(){ double a; cin >> a; if (a >= 0) cout << (int)(a + 0.5); else cout << (int)(a - 0.5); cout << endl; system("pause");}

2015-08-15 09:04:39 255

原创 提取不重复的整数

点击打开链接#include #includeusing namespace std;void main(){ int n,i=0; cin >> n; char a[100],b[100]; while (n != 0){ //将整数转换成字符 a[i++] = n % 10 + '0'; n = n / 10; } a[i] = '\0'; cout << a

2015-08-14 21:51:29 340

原创 第一个只出现一次的字符(剑指offer 35)360笔试

#include #includeusing namespace std;char find(char *s){ int hash[256] = { 0 }; char *phashkey = s; while(*phashkey!='\0'){ hash[*phashkey]++; phashkey++; } phashkey = s; while (*phashk

2015-08-14 15:05:38 270

原创 数字颠倒

点击打开链接#include #includeusing namespace std;void main(){ int n,t,i=0; cin >> n; char s[100]; while (n != 0){ t = n % 10; n = n / 10; s[i++] =t+'0';//将整数赋值给字符 } s[i] = '\0'; cout << s

2015-08-14 11:05:58 391

原创 句子逆序

#include #includeusing namespace std;void main(){ char s[100]; char t; gets_s(s); int i, j; int len = strlen(s); cout << len << endl; for (i = 0, j = len - 1; i < j; i++, j--){ t = s[i];

2015-08-14 10:10:39 260

原创 int型数据在内存中存储时1的个数

原题#include #includeusing namespace std;void main(){ int n,count=0; cin >> n; while (n != 0){ if (n % 2 == 1)count++; n = n / 2; } cout << count << endl; system("pause"); }

2015-08-13 20:02:15 338

原创 字符串的倒数第K个字符

原题目原题#include #includeusing namespace std;struct ListNode{ int m_nKey; ListNode *m_pNext;};void main(){ int n,k; cin >> n; ListNode*q,*p,*p1; p1 = p = new ListNode; for (int i = 0; i

2015-08-13 19:44:11 399

原创 杭电ACM求数列的和

Problem Description数列的定义如下:数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。Input输入数据有多组,每组占一行,由两个整数n(nOutput对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。Sample Input81 42 2Sample Outpu

2015-08-10 21:26:11 398

原创 输出m到n的水仙花数

Problem Description春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。现在要求输出所有在m和n范围内的水仙花数。Input输入数据有多组,每组占一行,包括两个整数m和n(100Output对于每个测试实例,要求输出所有在

2015-08-10 20:28:54 6003

原创 删除字符串中出现次数最少的字符

若多个字符出现次数都一样,则都删除。输出删除。原题#include#includeusing namespace std;void main(){ int visit[26] = { 0 };//记录每个字母出现的次数 string s; cin >> s; int len = s.size(); for (int i = 0; i < len; i++){ int

2015-08-10 12:06:03 361

原创 字符串最后一个单词的长度

用到了gets_s()函数,因为cin遇空格会结束。#include#includeusing namespace std;void main(){ char a[128]; gets_s(a); int len = strlen(a); cout << len << endl; int i = len-1,count=0; while (a[i] != ' '){ co

2015-08-09 19:16:54 274

原创 字符串加解密

#include#includeusing namespace std;void encrypt(char aucpassword[], char aucResult[]){ int len = strlen(aucpassword); for (int i = 0; i < len; i++){ if (aucpassword[i] >= 'a'&&aucpassword[i] <

2015-08-09 09:54:08 277

原创 指针合并字符串

写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。#include#includeusing namespace std;void main(){ char s1[100], s2[100]; cout << "请输入两个字符串:" << endl; cin >> s1 >> s2; cout << s1 << " " << s2 << endl; cha

2015-08-03 20:30:35 1118

原创 元素按奇偶排序

将数组中偶数从大到小排序,奇数从小到大排序,奇数和偶数交叉着放且输出数组第一位放奇数 若奇数和偶数不等长,则把剩下的直接放到数组中。输入数组a, 将偶数放入b数组,奇数放入c数组,分别对b,c排序,然后输出结果到result中,用flag标记。#include #include using namespace std; void main(){ int a[100];

2015-08-02 21:47:02 426

原创 整形数组异集

求两个整型数组的异集,即A+B-(A与B的交集)。 例如a[]={1,2,3,4,5}, b[]={2,3},则a,b的异集为{1,4,5}。用visit数组标记 数组b,如果有与数组a,相等的 就就标记置为1;用flag 来标记数组a的元素,如果有与b相等的,则将flag置为1 。#include #include using namespace std; void mai

2015-08-02 12:35:47 398

原创 名字的漂亮度

名字的漂亮度=26*字母个数最多的个数+25*字母个数其次的个数+24*字母个数再其次的(忽略大小写)个数+….+1*出现次数最小的个数。 输入:整数N,N个字符串 输出:N个字符串漂亮度例如: 输入1 a 输出 26先求出每个字母出现的个数,然后对个数从大到小排序,再求出字符的漂亮度。#include #include using namespace std;

2015-08-01 21:30:31 874

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除