随笔分类 -  c语言每日一题

考研复试
摘要:/* 输入一个整数n,输出该整数中重复的数字,如果没有重复出现的数字则输出no repeat number! */ #include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> 阅读全文
posted @ 2020-05-27 09:47 dreamy_java 阅读(932) 评论(0) 推荐(0)
摘要:/* 输入今天以前一个日期,算离今天的天数。 */ #include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include <time.h> main() { int y 阅读全文
posted @ 2020-05-27 08:43 dreamy_java 阅读(483) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include <time.h> main() { int a=1020,c=0; do{ a=a/2-2; c+ 阅读全文
posted @ 2020-05-26 10:26 dreamy_java 阅读(2993) 评论(0) 推荐(0)
摘要:思路:就是将素数的数组置为0. 1、初始化a[n]-a[n]为1-n; 2、a[1]=0; 3、将a[1]-a[n]中为素数的置为0,即a[i]=0; 4、输出数组,将不为0的输出。 #include<stdio.h> #include<math.h> #include<malloc.h> #inc 阅读全文
posted @ 2020-05-24 22:00 dreamy_java 阅读(300) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include <time.h> /* 冒泡排序 */ void rankNum(int num[],int n) 阅读全文
posted @ 2020-05-24 16:28 dreamy_java 阅读(197) 评论(0) 推荐(0)
摘要:/* 计算字符串中子串出现的次数。 */ #include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> /* 10进制转8进制 */ int convertDecimalToOc 阅读全文
posted @ 2020-05-24 14:25 dreamy_java 阅读(472) 评论(0) 推荐(0)
摘要:/* 79. 单词搜索 给定一个二维网格和一个单词,找出该单词是否存在于网格中。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。 */ #include<stdio.h> #include<malloc. 阅读全文
posted @ 2020-05-07 11:24 dreamy_java 阅读(218) 评论(0) 推荐(0)
摘要:求所有的子集,一下子就想到回溯,回溯有两个模板,一个是组合combition,一个是全排列oermutation。 /* 组合combination: n代表几个数,或者说树的深度。 path代表回溯过程中多叉树节点的值 depth代表path的下标 start开始位置。在组合中dfs是i+1,如果 阅读全文
posted @ 2020-05-01 20:58 dreamy_java 阅读(194) 评论(0) 推荐(0)
摘要:方法一: 两遍扫描: 扫描第一遍,记录0、1、2的个数; 扫描第二遍,重填数组。 /* */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<st 阅读全文
posted @ 2020-04-22 08:52 dreamy_java 阅读(217) 评论(0) 推荐(0)
摘要:动态规划: 1、状态定义 2、状态初始化 3、状态转移 /* */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h> #incl 阅读全文
posted @ 2020-04-22 08:29 dreamy_java 阅读(133) 评论(0) 推荐(0)
摘要:动态规划 /* */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<iostream> int getMi 阅读全文
posted @ 2020-04-21 17:14 dreamy_java 阅读(128) 评论(0) 推荐(0)
摘要:解决方法:动态规划。 int uniquePaths(int m, int n){ //1、状态定义 int **dp=(int**)malloc(sizeof(int*)*n),i,j; for(i=0;i<n;i++){ dp[i]=(int*)malloc(sizeof(int)*m); } 阅读全文
posted @ 2020-04-18 11:47 dreamy_java 阅读(89) 评论(0) 推荐(0)
摘要:int compare(const void *a,const void *b){ return *(int*)a>*(int*)b; } int **merge(int **intervals, int intervalsSize, int *intervalsColSize, int *retu 阅读全文
posted @ 2020-04-17 11:30 dreamy_java 阅读(266) 评论(0) 推荐(0)
摘要:/* 最大子序和。 动态规划: 1、状态定义 2、状态初始化 3、状态转移 */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h 阅读全文
posted @ 2020-04-09 16:10 dreamy_java 阅读(267) 评论(0) 推荐(0)
摘要:组合总和。 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 例: candidates = [2,3,6,7], target = 7, [ [7], [2,2,3] ] candidates = 阅读全文
posted @ 2020-04-05 17:34 dreamy_java 阅读(264) 评论(0) 推荐(0)
摘要:/* 34.在排序数组中查找元素的第一个和最后一个位置。 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。 你的算法时间复杂度必须是 O(log n) 级别。 如果数组中不存在目标值,返回 [-1, -1]。 */ #include< 阅读全文
posted @ 2020-04-05 11:05 dreamy_java 阅读(328) 评论(0) 推荐(0)
摘要:/* 搜索旋转排序数组--二分查找。 */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h> #include <iostrea 阅读全文
posted @ 2020-04-04 12:05 dreamy_java 阅读(199) 评论(0) 推荐(0)
摘要:/* 下一个排列--看图解。 */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h> #include <iostream> v 阅读全文
posted @ 2020-04-03 17:40 dreamy_java 阅读(167) 评论(0) 推荐(0)
摘要:/* 有效的括号--回溯法。 */ #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<string.h> #include <iostream> v 阅读全文
posted @ 2020-04-03 15:21 dreamy_java 阅读(418) 评论(0) 推荐(0)
摘要:/* 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 注意空字符串可被认为是有效字符串。 */ #include<stdio.h> #include<malloc.h 阅读全文
posted @ 2020-04-03 11:50 dreamy_java 阅读(237) 评论(0) 推荐(0)