
c++
CourageK
计算所
展开
-
const char*, char const*, char*const的区别
const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目。 事实上这个概念谁都有,只是三种声明方式非常相似很容易记混。 Bjarne在他的The C++ Programming Language里面给出过一个助记的方法: 把一个声明从右向左读。 char * const cp; ( * 读成 pointer to转载 2014-10-12 09:43:02 · 564 阅读 · 0 评论 -
面试前应该掌握的问题
1.最长回文子串:http://hihocoder.com/contest/hiho1/problem/1http://hihocoder.com/problemset原创 2015-04-25 15:10:24 · 435 阅读 · 0 评论 -
Remove Element的两种解法
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2015-05-12 20:51:15 · 3080 阅读 · 0 评论 -
面向“ACM等比赛中的测试用例”的重定向问题
#include#include#includeusing namespace std;int main(){ ifstream ifile("input.txt"); ofstream ofile("output.txt"); int a, b; while(ifile>>a>>b)// printf("%d\原创 2015-05-17 15:33:26 · 855 阅读 · 0 评论 -
对字符串进行排序,学会使用仿函数
#include#include#include#includeusing namespace std;bool myCompare(char a, char b){ return a>b;}struct myCompare2{ bool operator()(char a, char b) { return a>b; }};原创 2015-05-19 09:41:19 · 920 阅读 · 0 评论 -
Determine if a string has all unique characters
Problem:高效率实现“字符串中是否有重复字符”Implement an algorithm to determine if a string has all unique characters. What if youcan not use additional data structures?#include#include#include#include#include#include#incl原创 2015-05-19 10:28:45 · 667 阅读 · 0 评论 -
今日知识点
1.当无法判断输入的值是否合法时,就采用全局布尔变量;2.画图,一步一步描述出某个测试用例的过程,很简单就能找出解题方法,然后写算法,再写代码,再根据之前举的栗子进行代码测试,看是否与测试用例中表格中的过程一致;3.原创 2015-06-08 14:17:26 · 429 阅读 · 0 评论 -
C程序中,strlen是求取字符串长度,若对整形数组,求取的是什么?还有整形数组作函数参数的问题?
#include #include void main(){ void fun(char *a); int a[2]={2,3}; printf("%d\n",strlen(a)); printf("%d\n",sizeof(a)); fun(a);}void fun(int a[2]){ printf("%d\n",strlen(a)); printf("%d\n"转载 2015-08-09 09:53:46 · 5527 阅读 · 1 评论 -
g++ sleep头文件
unistd.h原创 2015-08-02 18:28:51 · 1581 阅读 · 0 评论 -
《编程之美》买书问题及c语言代码实现
最近刚买了本书《编程之美》,首先看了下时间:2008.3。刚好是大二的时候,真希望回到那时,买一本《编程之美》,坐在宿舍,吃着热干面,编着代码。刹那间,有种相见恨晚的感觉,前一阵,也感觉自己浮夸的很,什么流行就看什么。是时候按下心来,好好享受下beauty of programming 本文来自:http://blog.youkuaiyun.com/lengzijian/article/details转载 2015-08-02 21:32:25 · 956 阅读 · 0 评论 -
数组分割问题-详细版
数组分割问题-详细版 (2012-07-06 00:22:41)转载▼标签: 杂谈分类: 算法结构题记:这道题和《编程之美》一书中2.18节的数组分割区别不大,但本人觉得《编程之美》这一节讲的不够透彻,不好理解(或许本人愚钝),故给出自己的思路,同时也给出打印其中一种方案的方法(这一点《编程之美》并没有提到)。转载 2015-08-03 19:15:24 · 761 阅读 · 0 评论 -
检测单向链表是否存在环
问题描述:在单向链表中,每个结点都包含一个指向下一个结点的指针,最后一个结点的这个指针被设置为空。但如果把最后一个结点的指针指向链表中存在的某个结点,就会形成一个环,在顺序遍历链表的时候,程序就会陷入死循环。我们的问题就是,如何检测一个链表中是否有环,如果检测到环,如何确定环的入口点(即求出环长,环前面的链长)。一种比较耗空间的做法是,从头开始遍历链表,把每次访问到的结点(或其地址)存入一转载 2015-04-24 14:59:44 · 566 阅读 · 0 评论 -
unordered_map版本兼容问题
在C++中最让我蛋疼的事情之一就是unordered_map千呼万唤才出来,在C++早期版本标准库里面只有map这个字典。 但是map的内部实现是采用的红黑树,众所周知,对于字典这类结构也可以用hash表来实现,也就是C++的标准库应该也要有hash_map这种数据结构。红黑树实现的map占用内存较小,但是查找效率不高,O(logn)的查找效率。hash表实现的map占用内存较大,但是转载 2015-04-15 10:07:21 · 1155 阅读 · 0 评论 -
Direct Insertion
直接插入排序是稳定的排序,时间复杂度为O(n^2)原创 2015-03-31 20:35:26 · 465 阅读 · 0 评论 -
Const char *的使用
1.memcpy原创 2014-10-12 10:16:53 · 2170 阅读 · 0 评论 -
数组的初始化
3.初始化数组的一部分元素,则被初始化的元素的最大下标的下一个元素值为0,表示被数组的终结,但是最后其他未被初始化的元素则被赋值为随机值。a. int arr[7]; for(int i = 0; i { arr[i] = 3; } for(int i = 0; i { cout原创 2014-10-12 11:59:22 · 650 阅读 · 0 评论 -
string的下标约定
1.std::string s3 (s0, 8, 3);原创 2014-10-12 15:19:33 · 1044 阅读 · 0 评论 -
const_interator的用法
A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by string::begin, but i原创 2014-10-12 15:34:52 · 767 阅读 · 0 评论 -
string copy的用法
Copy sequence of characters from stringCopies a substring of the current value of the string object into the array pointed by s. This substring contains the len characters that start at position p原创 2014-10-12 16:12:07 · 6077 阅读 · 0 评论 -
string strtok的用法
函数strtok将字符串分解为一系列标记(token),标记就是一系列用分隔符(delimiting chracter,通常是空格或标点符号)分开的字符。注意,此的标记是由delim分割符分割的字符串喔。例如,在一行文本中,每个单词可以作为标记,空格是分隔符。需要多次调用strtok才能将字符串分解为标记(假设字符串中包含多个标记)。第一次调用strtok包含两个参数,即要标记化的字符原创 2014-10-12 16:21:15 · 2081 阅读 · 0 评论 -
string:clear的用法
clear string:Erases the contents of the string, which becomes an empty string (with a length of 0 characters).原创 2014-10-12 15:45:36 · 3040 阅读 · 0 评论 -
数组名作为函数参数时会退化为指针
void arraySum(int a[],int b[]) { cout cout int length_a = sizeof(a)/sizeof(int); }// 等价于:void arraySum(int *a,int *b) { cout cout int length_a = sizeof(a)/sizeof(int);原创 2015-03-16 21:54:23 · 2580 阅读 · 0 评论 -
Leetcode:Combinations
1.ProblemGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1原创 2015-03-12 21:41:29 · 465 阅读 · 0 评论 -
hulu面试题1
1、给定一个N位数,例如12345,从里面去掉k个数字,得到一个N-k位的数,例如去掉2,4,得到135,去掉1,5,得到234。设计算法,求出所有得到的N-k位数里面最小的那一个?解决方案一:(1)第一步要确定剩余N-K位的数的最高位:从个位开始算起,从第N-K位开始向高位比较,求出最小数字,作为高位。例如,3 1 1 2 3 3 1,K=3时,从7-3=4开始(为2),向上转载 2015-08-05 08:58:19 · 1009 阅读 · 0 评论