12 2011 档案
去掉C/C++源程序中的注释
摘要:对原文http://www.cnblogs.com/yangyangye/articles/1771823.html中的程序修改了两个地方,可以去掉 形如“//三角形面积”这样的汉字注释原文内容为:一道题目,输入是一个正确的C/C++源程序,输出是将所有注释去掉之后的程序。不细想觉得很简单,字符串搜索,找到//后再找一个回车,删掉,找到/*后再找一个*/,删掉,还有什么好做的,太简单了。给个测试例子:#include "stdafx.h"#include <iostream>using namespace std;int main(){ cout<< 阅读全文
posted @ 2011-12-23 14:19 Ming明、 阅读(1930) 评论(0) 推荐(0) 编辑
求一个字符串中连续出现次数最多的子串
摘要:分析:一个字符也算是字串,然而这是求连续最多的子串,abcbcbc,出现最多的为bc,连续出现3次,而如果是abcaaaaa,则a是出现次数最多的,次数为5.可以首先逐个子串扫描来记录每个子串出现的次数。如:abc字符串,对应的子串为abc/bc/c,各出现一次,然后再逐渐缩小字符串来得出正确的结果。代码如下:#include "stdafx.h"#include <iostream>#include <string>#include <vector>using namespace std;pair<int,string> f 阅读全文
posted @ 2011-12-19 22:30 Ming明、 阅读(3808) 评论(2) 推荐(0) 编辑
【第八章】zigzag数组输出
摘要:#include "stdafx.h"#include <ostream>#include <stdio.h>int main(){int N;int s,i,j;int squa;/*分配空间*/scanf("%d",&N);int **a = (int**)malloc(N*sizeof(int));if(a==NULL)return 0;for (i=0;i<N;i++){if((a[i]=(int*)malloc(N*sizeof(int)))==NULL){while(--i>=0)free(a[i] 阅读全文
posted @ 2011-12-05 11:31 Ming明、 阅读(356) 评论(0) 推荐(0) 编辑
【第六章】const函数改变变量的值——mutable
摘要:mutalbe的中文意思是“可变的,易变的”,跟constant(既C++中的const)是反义词。在C++中,mutable也是为了突破const的限制而设置的。被mutable修饰的变量,将永远处于可变的状态,即使在一个const函数中。 我们知道,如果类的成员函数不会改变对象的状态,那么这个成员函数一般会声明成const的。但是,有些时候,我们需要在const的函数里面修改一些跟类状态无关的数据成员,那么这个数据成员就应该被mutalbe来修饰。#include "stdafx.h"#include <iostream>#include <ioman 阅读全文
posted @ 2011-12-03 10:44 Ming明、 阅读(505) 评论(0) 推荐(0) 编辑
【第五章】指针类型转换
摘要:#include "stdafx.h"#include <stdio.h>int main(){unsigned int a = 0xFFFFFFF7; unsigned char i = (unsigned char)a;char *b = (char *)&a;printf("%08x,%08x",i,*b);getchar();return 0;}输出结果为:000000f7,fffffff7分析:unsigned int 变量赋值给unsigned char 3个字节将会被截断为1字节(3位和高于3位的将被程序自动丢弃)。第二 阅读全文
posted @ 2011-12-02 22:46 Ming明、 阅读(300) 评论(0) 推荐(0) 编辑
【第五章】printf输出顺序
摘要:看到第五章程序员面试宝典里有题如下:#include "stdafx.h"#include <stdio.h>int _tmain(int argc, _TCHAR* argv[]){int b = 3;int arr[] = {6,7,8,9,10};int *ptr = arr;*(ptr++) += 123;printf("%d,%d \n",*ptr,*(++ptr));getchar();return 0;}输出结果为: 8,8相信很多人都做错了吧。分析如下:C中printf计算参数时,是从右往左压栈的。其中,*(ptr++)+=1 阅读全文
posted @ 2011-12-02 22:27 Ming明、 阅读(664) 评论(0) 推荐(1) 编辑