![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C
qq_2423338532
这个作者很懒,什么都没留下…
展开
-
异或交换两个变量的值
采用下面的方法,对于给定两个整数a,b,下面的异或运算可以实现a,b的交换,而无需借助第3个临时变量:a = a ^ b;b = a ^ b;a = a ^ b;这个交换两个变量而无需借助第3个临时变量过程,其实现主要是基于异或运算的如下性质:1.任意一个变量X与其自身进行异或运算,结果为0,即X^X=02.任意一个变量X与0进行异或运算,结果不变,即X^0=X3.异或运算具有可结...原创 2019-12-03 20:49:22 · 668 阅读 · 0 评论 -
逻辑运算vs按位运算
原创 2019-11-22 19:58:50 · 196 阅读 · 0 评论 -
return A > B ? A > C ? A : C : B > C ? B : C;
if(a > b) if(a > c) return a; else return c;else if(b > c) return b; else return c;转载 2018-10-01 20:19:47 · 2711 阅读 · 0 评论 -
最大子列和问题 有错版
#include<stdio.h>#define Maxn 100int MaxSubseSum4(int A[], int N);int DivideAndConquer( int List[], int left, int right );int Max3( int A, int B, int C); int main(){ int n, i, ans; int a[...原创 2018-10-01 21:16:03 · 69 阅读 · 0 评论 -
A - 非常可乐 --WA版本
大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>...原创 2018-09-29 21:14:00 · 124 阅读 · 0 评论 -
H - 人见人爱A+B
HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒。Input输入数据有多行组成,首先是一个整数N,表示测试实例的个数,...原创 2018-09-29 21:15:04 · 102 阅读 · 0 评论 -
K - 汉字统计 WA版本
统计给定文本文件中汉字的个数。Input输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。Output对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。[Hint:]从汉字机内码的特点考虑~Sample Input2WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa!马上就要期末考试了Are you ready?...转载 2018-09-29 21:16:24 · 137 阅读 · 0 评论 -
L - 超级楼梯 WA版本
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?Input输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。Output对于每个测试实例,请输出不同走法的数量Sample Input223Sample Output12#include<stdi...原创 2018-09-29 21:17:44 · 91 阅读 · 0 评论 -
图的邻接矩阵表示法
/* 图的邻接矩阵表示法 */#define MaxVertexNum 100 /* 最大顶点数设为100 */#define INFINITY 65535 /* ∞设为双字节无符号整数的最大值65535*/typedef int Vertex; /* 用顶点下标表示顶点,为整型 */typedef int WeightType; /* ...转载 2018-11-29 18:50:33 · 462 阅读 · 0 评论 -
图的邻接表表示法
/* 图的邻接表表示法 */#define MaxVertexNum 100 /* 最大顶点数设为100 */typedef int Vertex; /* 用顶点下标表示顶点,为整型 */typedef int WeightType; /* 边的权值设为整型 */typedef char DataType; /* 顶点存储的数据类型设为字...转载 2018-11-29 18:52:42 · 141 阅读 · 0 评论 -
6-7 在一个数组中实现两个堆栈
(20 point(s)) 本题要求在一个数组中实现两个堆栈。https://pintia.cn/problem-sets/15/problems/730函数接口定义:Stack CreateStack( int MaxSize );bool Push( Stack S, ElementType X, int Tag );ElementType Pop( Stack S, int Tag...原创 2018-12-04 16:39:09 · 353 阅读 · 0 评论 -
实验三——进制转换
#include<stdio.h>#include<stdlib.h>#define MAXSIZE 100#define N 8 typedef struct Sqstack{ int *base; //栈底指针 int top; //栈顶指针 int stacksize; //栈可用最大容量 }SqStack; typedef...原创 2018-12-11 05:48:30 · 262 阅读 · 0 评论 -
图的邻接矩阵
/* 图的邻接矩阵表示法 */#include<stdio.h>#include<stdlib.h>#define MaxVertexNum 100 /* 最大顶点数设为100 */#define INFINITY 65535 /* ∞设为双字节无符号整数的最大值65535*/typedef int Vertex; /* 用顶点...原创 2018-12-18 11:21:52 · 186 阅读 · 0 评论 -
实验五 - 图的邻接矩阵表示法 + DFS
/* 图的邻接矩阵表示法 + DFS*/#include<stdio.h>#include<stdlib.h>#define MaxVertexNum 10 /* 最大顶点数设为100 */#define INFINITY 65535 /* ∞设为双字节无符号整数的最大值65535*/typedef int Vertex; /*...原创 2018-12-18 17:30:42 · 282 阅读 · 0 评论 -
ds冒泡排序
#include<stdio.h>#include<stdlib.h>#define maxn 10 //冒泡排序 从小到大/* 测试数据95 7 8 7 0 2 1 6 9*/typedef struct LNode *List;struct LNode{ int Data[maxn]; int Last;//线性表最后一个元素的位置};...原创 2018-12-25 11:19:35 · 230 阅读 · 0 评论 -
不能用gets 的时候getchar的用法
#include<stdio.h>#include<string.h>int main(){ char a[10]; char ch; int i = 0, n; ch = getchar(); while(ch != '\n'){ a[i] = ch; i++; ch = getc...原创 2018-09-15 10:43:02 · 448 阅读 · 0 评论 -
D - String暴力超时版
There is a string S.S only contain lower case English character.(10≤length(S)≤1,000,000)How many substrings there are that contain at least k(1≤k≤26) distinct characters?InputThere are multiple tes...原创 2018-10-01 09:42:41 · 161 阅读 · 0 评论 -
使用递归计算阶乘
#include<stdio.h>double fact(int n);int main(){ int n; scanf("%d", &n); printf("%f\n", fact(n)); return 0;}double fact(int n){ double result; if(n == 1 || n == 0)...原创 2018-09-04 17:00:17 · 509 阅读 · 0 评论 -
统计一个整数的位数
#include&lt;stdio.h&gt;int main(){ int count, number; count = 0; scanf("%d", &amp;number); if(number &lt; 0){ number = -number; } do{ number = number / 10;原创 2018-09-22 10:16:58 · 3327 阅读 · 1 评论 -
产生一个随机数
#include&amp;amp;lt;time.h&amp;amp;gt;#include&amp;amp;lt;stdlib.h&amp;amp;gt;int main(){ int rea; srand(time(0)); rea = rand() % 100 + 1; printf(&amp;quot;%d&amp;quot;, rea); ret原创 2018-09-22 10:16:41 · 207 阅读 · 0 评论 -
Hanio 递归
#include&lt;stdio.h&gt;void hanio(int nm char a, char b, char c);int main(){ int n; scanf("%d", &amp;n); hanio(n, 'a', 'b', 'c'); return 0;}void hanio(int nm char a, char b, char c...转载 2018-09-05 09:33:44 · 313 阅读 · 0 评论 -
长度单位转换
#include<stdio.h>#define Mile_to_meter 1609 //1英里 = 1690米#define Foot_to_centimeter 30.48 //1英里 = 1690米#define Inch_to_centimeter 2.54 //1英里 = 1690米int main(){ float mile, foot, inch; ...转载 2018-09-05 10:04:24 · 795 阅读 · 0 评论 -
简单的带参数的宏定义
#include<stdio.h>#define MAX(a, b) a > b ? a : b #define SQR(x) x * xint main(){ int x, y; scanf("%d %d", &x, &y); x = MAX(x, y); y = SQR(x); printf("%d %d\n", ...转载 2018-09-05 10:24:42 · 748 阅读 · 0 评论 -
使用"异或"运算而不需要临时变量交换两个变量的值
#include&lt;stdio.h&gt;int main(){ int a, b; scanf("%d %d", &amp;a, &amp;b); a^=b^=a^=b; printf("a = %d b = %d\n", a, b); return 0;}原创 2018-09-03 10:59:25 · 548 阅读 · 0 评论 -
12.1学生成绩文件统计
#include<stdio.h>#include<stdlib.h>int main(){ FILE *fp; long num; char stname[20]; int i, score; int avg_score = 0; if((fp = fopen("c:\\f12-1.txt", "r")) == NULL...转载 2018-09-11 21:12:37 · 818 阅读 · 0 评论 -
使用指针对数组求和的三种方法
#include<stdio.h>int main(){ int a[10]; int i, *p; int s = 0; int u = 0; int m = 0; for(i = 0; i < 10; i++){ scanf("%d", &a[i]); } for(p = a; p &l...原创 2018-09-03 19:22:28 · 10500 阅读 · 0 评论 -
指针进阶
二维数组的指针形式&amp;a[0] 和 &amp;a[0] [0] 等价 a + i //第i行的地址 *(a + i) //第i行首元素的地址 *(*a + i) //第i行首元素的值a行元素数组的首地址–行地址–二级指针 *a首行第一个元素的地址–列地址–一级指针 下标表示法:a[ i ] [ j ] 指针表示法:* ( * (a + i) + j ) 混合运用:*...原创 2018-09-22 10:15:11 · 131 阅读 · 0 评论 -
用动态分配内存方法处理多个字符串的输入
#include<stdio.h>#include<stdlib.h>int main(){ int i, n = 0; char *color[20], str[15]; scanf("%s", str); while(str[0] != '#'){ color[n] = (char *) malloc( sizeof(...转载 2018-09-06 20:25:40 · 3550 阅读 · 3 评论 -
字符定位--函数指针 + cal(f, a, b)用梯形公式求函数f(x)在[a, b]上的数值积分
字符定位#include&lt;stdio.h&gt;char *match(char *s, char ch);int main(void){ char ch, str[80],*p = NULL; scanf("%s", str); getchar(); ch = getchar(); if((p = match(str, ch)) != NU...转载 2018-09-22 10:17:24 · 1092 阅读 · 0 评论