
每日一题
little_two_two
这个作者很懒,什么都没留下…
展开
-
查找数组中第二大或者第二小的数值
给出一个无序数组,找出其中的第二大或者第二小的数值,下面给出详细代码,仅供参考。#include int FindSecondBiggest(int* v, int len){ if (v == NULL || len < 2) { return -1; } int i,max = v[0],second = v[1]; i原创 2015-02-08 18:12:04 · 3172 阅读 · 0 评论 -
将字符串转为数字
考虑到越界、非数字字符、符号等因素#include #include int strToInt(const char* str){ int temp = 0; const char* ptr = str; if(str[0] == '+' || str[0] == '-')//判断正负 str++; if(*str =原创 2015-02-10 00:35:03 · 797 阅读 · 0 评论 -
不利用第三个变量交换两个数字的值
int main(int argc, const char * argv[]) { int a,b; a=1; b=2; a=a-b; b=a+b; a=b-a; printf("a=%d,b=%d\n",a,b); a = 3; b = 4; a = a^b; b = a^b; a = a^b;原创 2015-02-10 16:30:36 · 597 阅读 · 0 评论 -
CPU大小端的判定
大端:高字节存储在低地址,低字节存储在高地址小端:低地址存储低字节,高地址存储高字节#include bool IsLittle_Endian(){ union tmp { int a; char b; }; tmp c; c.a = 1; return (c.b == 1);}bool IsBig原创 2015-02-10 16:44:20 · 693 阅读 · 0 评论 -
字符串数字从小到大输出
1、将一个随机的整数转换成一个按各位上数值大小排序的整数,如整数5862转换成2568,用C/C++语言实现,要求不使用异步到位的库函数#include using namespace std;void func(char* str){ if (NULL == str) { return ; } unsigned int s[1原创 2015-02-11 21:58:43 · 1049 阅读 · 0 评论 -
汉诺塔问题
#include void move(int,char,char,char); int main() { //A、B、C分别代表三个柱子 char ch1 = 'A'; char ch2 = 'B'; char ch3 = 'C'; //n代表圆盘的个数 int n; printf("请输入圆盘个数:"); scanf("%d原创 2015-04-16 00:20:08 · 539 阅读 · 0 评论