- 博客(10)
- 收藏
- 关注
原创 牛客网笔试题-求最小公倍数
题目描述正整数A和正整数B的最小公倍数是指能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数。输入描述:输入两个正整数A和B。输出描述:输出A和B的最小公倍数。示例1输入5 7输出35#include <iostream>using namespace std;int MaximumCommonDivisor(int iA, int iB){ int iMax = iA > iB ?...
2020-06-29 23:06:14
356
原创 输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数
#include<stdio.h>#include<stdlib.h>int ItemContain1Count(int i){ int num=0; while(i) { if(i%10==1) { num++; } i=i/10; } return num;}int main(){ int n; int count=0; printf("请输入N的值:\n...
2018-05-27 21:48:41
1117
原创 输入一个整数,求该整数的二进制表达中有多少个1。
#include<stdio.h>#include<stdlib.h>int NumberOf(int num){ int count=0; unsigned int flag=1; while(flag) { if(num&flag) { count++; } flag=flag<<1; } return count;}int main(...
2018-05-27 21:24:12
1791
原创 不用乘法或加法增加8倍。现在用同样的方法增加7倍
增加8倍是左移3位。增加7倍,a=1,b=2,c=4;d=a|b|c 按位与d=a^b^c; 异或
2018-05-23 20:04:13
621
原创 求子数组的最大和
#include<stdio.h> #include<stdlib.h>int find(int *p,int n) { int max=0,temp=0; for(int i=0;i<n;i++) { if(temp<=0) { temp=p[i]; } else { temp+=p[i]; } if(max<...
2018-05-22 20:04:39
223
原创 定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。
#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}Stack;#define Maxsize 1000000 //定义一个特大的数 void Push(Stack **top,int data){ Stack *p; p=(Stack *)malloc...
2018-05-22 19:55:57
783
原创 二叉查找树转化为双向链表
/* 把二元查找树转变成排序的双向链表 题目: 输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。 要求不能创建任何新的结点,只调整指针的指向。 10 / \ 6 14 / \ / \ 4 8 12 16 转换成双向链表 4=6=8=10=12=14=16。 首先我们定义的二元查找树 节点的数据结构如下: struct BSTre...
2018-05-22 18:22:20
177
原创 希尔排序
#include "stdafx.h"#include <stdio.h>#include <stdlib.h>int Input(int a[]); //输入函数void ShellSort(int a[], int N);void ShellInsertSort(int a[],int N,int dk);void Output(int a[], int N); /...
2018-03-04 17:57:03
114
原创 简单选择排序
#include "stdafx.h"#include <stdio.h>#include <stdlib.h>int Input(int a[]); //输入函数void SSSort(int a[],int N);int SelectMinKey(int a[], int N,int i);void Output(int a[], int N); //输出函数i...
2018-03-04 17:54:51
165
原创 冒泡排序
// BubbleSort.cpp: 定义控制台应用程序的入口点。//#include "stdafx.h"#include <stdio.h>#include <stdlib.h>int main(){ int N; //设置所需要排序的数的个数 int temp,i,j; printf("请输入所要排序的个数:\n"); scanf_s("%d",&N); in...
2018-03-04 16:25:13
119
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人