
C++
文章平均质量分 67
denisyq
这个作者很懒,什么都没留下…
展开
-
C库函数
1、调试相关的宏_FILE_:用来代表当前源代码的文件名(字符串表示)_LINE_:代表当前源代码中行号(正整数表示)_func_:代表当前所在函数的函数名_DATE_:代表编译时进行预处理的日期,格式为“MMM DD YYYY “_TIME_:代表编译源文件的当前时间,格式为“hh:mm:ss”2、主要提供两类重要的函数:字符测试函数和字符转载 2012-07-23 09:03:17 · 655 阅读 · 0 评论 -
Iteration vs. Recursion in Java
1. RecursionConsider the factorial function: n!=n*(n-1)*(n-2)*...*1There are many ways to compute factorials. One way is that n! is equal to n*(n-1)!. Therefore the program can be directly wri转载 2013-11-28 14:31:51 · 1269 阅读 · 1 评论 -
swap交换两个变量
最简单的交换两个变量值是用指针。void swap(int *a, int *b){ int tmp; tmp = *a; *a = *b; *b = tmp;}//work这里有个问题,一定要想清楚。为什么在函数体内不能交换指针了?变成这样void swap(int *a, int *b){ int *tmp; tmp =原创 2014-01-11 17:47:44 · 970 阅读 · 0 评论 -
leveldb -- 1
Leveldb:1.安装原创 2014-07-21 11:22:31 · 638 阅读 · 0 评论 -
C++ template
template相当于overload,有点类似的意思原创 2014-07-22 11:24:26 · 547 阅读 · 0 评论 -
leveldb -- 2 [LRUCache C++ 实现]
在看leveldb实现过程中发现小和尚的藏经阁里提到 LRUCache的原创 2014-07-28 11:37:52 · 1348 阅读 · 1 评论 -
Git 初步
Git 管理代码,第一次用,有些概念难免要记录下:git initgit branch -agit branch -vgit branch m原创 2014-08-21 15:01:04 · 518 阅读 · 0 评论 -
brackets 匹配问题
#include #include #include using namespace std;int checkNotRight(string);int process(string, int&, int&);int main(void){ string s; int first_end=0,num_swap=0; cin>>s; if(process(s,first_end原创 2014-09-25 00:25:06 · 712 阅读 · 0 评论 -
OS_threading
/*************** OS::threading***************/> #include # pthread_t1. pthread_self()pthread_t pthread_self()2. pthread_equal(pthread_t, pthread_t)pthread_t tid = pthread_self()p原创 2016-06-07 16:11:23 · 374 阅读 · 0 评论 -
OS_ioStream
/********************** file io strema [cpp]**********************/#include 1. 文件打开:fstream file("a.txt", ios::in|ios::out);fstream file; file.open("a.txt",ios::in|ios::out);ios::in原创 2016-05-31 20:17:44 · 353 阅读 · 0 评论 -
Pascal Triangle
题目是杨辉三角的分布,形如: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1原创 2013-11-20 11:04:57 · 1110 阅读 · 0 评论 -
why we need copy constructor & assignment operator
When we study the C++, please think more about the mechanism or the reason why the grammar is needed.The base it based on is the essential to this language. Q: why we need copy constructor & ass原创 2013-08-03 16:48:36 · 647 阅读 · 0 评论 -
十六进制转十进制
花了点时间把 hex 转 dec的代码写了下,特别是 ‘A’ ‘a’ 的操作。#includeint multiple16(int i){ // 16 will be multipled i times int sum=1; if (i == 0) return 1; while(--i) sum *= 16; r原创 2012-12-14 10:00:59 · 527 阅读 · 0 评论 -
字符串处理1 - strip str2 from str1 and link the rest
有两个字符串,str1, str2, 扣掉str1中的str2---------------------->>-------------------------------------------------------------------------------->>在最后要粘贴后面字符串时,由于忘记申请dest[100],造成segmentation fault。申请的指针是不能用原创 2012-12-17 10:11:54 · 1065 阅读 · 0 评论 -
C++ 1st -- 初识C++
以前学习新语言的意愿不强,现在需要重新拾起C++,感觉很多东西要学习,将所得经历记录如下。std::coutC++开始入门的时候,C++Primer不是一个很好的入门教材。我在这里吃了一些亏,因为C++语法博大,很多东西不是能一下子掌握的,而且很大东西不是Primer讲一下就能理解的,再加上Primer讲的全,但是不深,所以掌握的云里雾里,容易产生挫折感。我是后来直接看Scott Me原创 2013-01-10 14:19:09 · 521 阅读 · 0 评论 -
read/write file
操作文件夹#includeint main(void){ char filename[100]; static int num=1; snprintf(filename,100,"day_%d",num); FILE* fp; fp = fopen(filename,"rb"); if(!fp){ printf("err原创 2012-12-20 09:45:55 · 807 阅读 · 0 评论 -
字符串处理3 - 将0X数字中小于E的换成F
有一次碰上的面试题,面试者说很简单,但是当时我没有答对。比如有个数0x1AEF,将小于D的变成F, 需要将它变成0XFFEFvoid main(void){ int i=0,j=0; int num; scanf("%x",&num); int buffer[100]; while(num) { if(num%16 <原创 2012-12-25 08:59:14 · 521 阅读 · 0 评论 -
字符串处理2 - strcat/strcmp/strcpy/strchr/strrchr/strstr
strcat:一个简单的strcat,我在实际的coding中,还是发现了问题,先罗列一下1.主要在strcat_m,一开始在line8,while(tmp++ != '\0') 和下面line9是不一样的。line8:在tmp指向'\0'后,又向后移位一个单位,所以最后tmp指向'\0'后一个单位line9: 这个是正确的指向'\0'2.在line13,如果需要strcat_原创 2012-12-20 13:37:08 · 793 阅读 · 1 评论 -
[题目]在字符串中将数字相加
Q:在一个string中,将所有digits相加,如abc12ab1ab1234,应该得到12+1+1234=1237A:#include#include#includeint checkAlpha(char *str){ if((*str = 'A') || (*str = 'a')) return 1; else re原创 2013-04-19 11:16:47 · 929 阅读 · 0 评论 -
[题目]build the broken stacks
Q:The stairs stacked with block has been partially destroyed by the typhoon.Write a program to return the minimum number of necessary blocks to restore the destroyed stairs. However, the first原创 2013-04-19 14:41:16 · 643 阅读 · 0 评论 -
[Shell]带颜色打印
#!/bin/bash#!/usr/bin/awkRED='\E[7;31m'GRN='\E[1;32m'CYN='\E[1;36m'BLU='\E[1;34m'MAG='\E[4;35m'DRED='\E[0;31m'DMAG='\E[7;35m'END='\E[0m'function ECHOR { echo -e "$RED $1 ${BLU原创 2013-07-12 17:35:50 · 761 阅读 · 0 评论 -
[题目]一个不能少
#面试编程题#一个不能少:有k个有序的数组,请找到一个最小的数字范围。使得这k个有序数组中,每个数组都至少有一个数字在该范围中。例如:1: 4, 10, 15, 24, 26;2: 0, 9, 12, 20;3: 5, 18, 22, 30。所得最小范围为[20,24],其中,20在2中,22在3中,24在1中。请关注微信公众账号“待字闺中”。 #include i原创 2013-07-17 14:10:39 · 525 阅读 · 0 评论