huawei
sherry_0720
这个作者很懒,什么都没留下…
展开
-
海滩上原有多少个桃子(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 · 788 阅读 · 0 评论 -
整形数组异集
求两个整型数组的异集,即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 · 387 阅读 · 0 评论 -
元素按奇偶排序
将数组中偶数从大到小排序,奇数从小到大排序,奇数和偶数交叉着放且输出数组第一位放奇数 若奇数和偶数不等长,则把剩下的直接放到数组中。输入数组a, 将偶数放入b数组,奇数放入c数组,分别对b,c排序,然后输出结果到result中,用flag标记。#include #include using namespace std; void main(){ int a[100];原创 2015-08-02 21:47:02 · 412 阅读 · 0 评论 -
句子逆序
#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 · 254 阅读 · 0 评论 -
名字的漂亮度
名字的漂亮度=26*字母个数最多的个数+25*字母个数其次的个数+24*字母个数再其次的(忽略大小写)个数+….+1*出现次数最小的个数。 输入:整数N,N个字符串 输出:N个字符串漂亮度例如: 输入1 a 输出 26先求出每个字母出现的个数,然后对个数从大到小排序,再求出字符的漂亮度。#include #include using namespace std;原创 2015-08-01 21:30:31 · 860 阅读 · 0 评论 -
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 · 330 阅读 · 0 评论 -
手机号码验证
我国大陆运营商的手机号码标准格式为:国家码+手机号码,例如:8613912345678。特点如下: 1、 长度13位; 2、 以86的国家码打头; 3、 手机号码的每一位都是数字。请实现手机号码合法性判断的函数要求: 1) 如果手机号码合法,返回0; 2) 如果手机号码长度不合法,返回1 3) 如果手机号码中包含非数字的字符,返回2; 4) 如果手机号码不是以86打原创 2015-08-01 11:04:28 · 540 阅读 · 0 评论 -
字符串的倒数第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 · 388 阅读 · 0 评论 -
输入整数二进制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 · 293 阅读 · 0 评论 -
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 · 432 阅读 · 0 评论 -
数组旋转
#include #include using namespace std;void main(){ cout << "请输入一组数据:" << endl; int i = 1,n; int a[100]; cin >> a[0]; while (getchar() != '\n'){ cin >> a[i]; i++; } cout << "请输入旋转坐标:" <原创 2015-07-30 21:05:43 · 216 阅读 · 0 评论 -
字符串过滤
题目描述(60分):通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。比如字符串“abacacde”过滤结果为“abcde”。要求实现函数: void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);原创 2015-07-19 11:15:43 · 572 阅读 · 0 评论 -
放苹果(递归)
点击打开链接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 · 888 阅读 · 0 评论 -
输出能被其它元素整除的数(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 · 1555 阅读 · 0 评论 -
蛇形矩阵
点击打开链接#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 · 307 阅读 · 0 评论 -
删除字符串中出现次数最少的字符
若多个字符出现次数都一样,则都删除。输出删除。原题#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 · 349 阅读 · 0 评论 -
质数因子
点击打开链接#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 · 277 阅读 · 0 评论 -
数字颠倒
点击打开链接#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 · 384 阅读 · 0 评论 -
整数排序,有逗号
输入一组大于等于0的整数,根据从大到小的顺序排序后输出,如果排序后有连续数时,只输出连续数中最大和最小的两个数。输入的所有整数都各不相同,即不用考虑两个整数相同的情况。输入输出的数都以“,”分隔。输入字符串的总长度小于等于100个字节。#includeusing namespace std;void main(){ int a[1000],i=0,j,k,temp; cin >原创 2015-07-03 11:22:54 · 417 阅读 · 0 评论 -
最高分是多少(2016)
题目描述:老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩. 输入描述: 输入包括多组测试数据。 每组输入第一行是两个正整数N和M(0 学生ID编号从1编到N。 第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩 接下来又M行,每一行有一个字符C(只取‘Q’或‘U’),和两个正原创 2015-09-06 10:57:50 · 812 阅读 · 0 评论 -
指定分隔符,输出指定的段(2016)
题目一:根据指定的分隔符分隔字符串,并输出指定的段描述根据指定的分隔符分隔字符串,并输出指定的段。如果指定的段超过分隔的段数,输出:NULL举例: AAA?BBB?CCC??2 字符串为:AAA?BBB?CCC? 分隔符为:? 指定的段为:2 字符串分割为:AAA BBB CCC共三段,第2段字符串为:BBB输入输出格式要求输入分隔字符串长度小于128个字符原创 2015-08-20 10:33:44 · 1385 阅读 · 1 评论 -
找出最长的连续数字串
只要找到最长数字串的起始位置,还有长度,就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 · 466 阅读 · 0 评论 -
排序(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 · 459 阅读 · 0 评论 -
字符统计
点击打开链接#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 · 268 阅读 · 0 评论 -
字符逆序
点击打开链接#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 · 302 阅读 · 0 评论 -
最小公倍数
点击打开链接#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 · 225 阅读 · 0 评论 -
最大连续的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 · 633 阅读 · 0 评论 -
求解立方根
点击打开链接#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 · 368 阅读 · 0 评论 -
将真分数分解为埃及分数
点击打开链接若真分数的分子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 · 543 阅读 · 0 评论 -
提取不重复的整数
点击打开链接#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 · 334 阅读 · 0 评论 -
指针合并字符串
写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。#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 · 1060 阅读 · 0 评论 -
合并表记录
点击打开链接#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 · 267 阅读 · 0 评论 -
取近似值
点击打开链接#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 · 248 阅读 · 0 评论 -
字符串加解密
#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 · 268 阅读 · 0 评论 -
字符串最后一个单词的长度
用到了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 · 261 阅读 · 0 评论 -
元素异同比较
输入两个整形数组,找出这两个数组中对应位置不相等的个数。#includeusing namespace std;int diff(int a[],int len1,int b[],int len2){ int num=0,i=0; int k=len1>len2?len1:len2; while(k>=0){ if(a[i]!=b[i]){ num++; i++原创 2015-04-06 20:53:59 · 414 阅读 · 0 评论 -
等差数列
请写一个程序,判断给定整数序列能否构成等差数列。输入说明:多组数据,每组输入数据由两行构成,第一行只有一个整数n(输出说明:对于每一组数据,输出一个yes或no,表示该序列能否构成等差数列。#include#include#includeusing namespace std;void main(){ vectors; int n,a[1000],i,j,t; cin>>原创 2015-04-06 16:39:03 · 807 阅读 · 0 评论 -
水鲜花数
判断给定正整数是不是“水仙花数”。“水仙花数”是指一个三位数,其各位数字的立方和等于该数,例如153=1^3+5^3+3^3。输入说明:有多组数据,每组数据为一个正整数n(0输出说明:对于每一组数据,输出一个yes或no(表示该数是否为“水仙花数”)。输入样本:1531113704220输出样本:yesnoyesno#include#i原创 2015-04-06 11:20:05 · 690 阅读 · 0 评论 -
01背包(等于总值)
给定一个总值,和一个整数数组,从数组中找出和等于总值的那几个数,如果存在,数相应的下标为1,其余的为0,如果不存在,输出no。#include#include#includeusing namespace std;int a[50];int f[50]={0};int find(int n,int m){ if(n==0) //刚好递归结束 return 1; else原创 2015-04-06 10:36:11 · 273 阅读 · 0 评论 -
字符串压缩
通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。压缩规则:1. 仅压缩连续重复出现的字符。比如字符串"abcbc"由于无连续重复字符,压缩后的字符串还是"abcbc".2. 压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"要求实现函数:原创 2015-04-18 20:10:41 · 383 阅读 · 0 评论