C++
zhuxin
just for you
展开
-
谁有本事解决codeblocks的这个问题?
今天在写活动安排问题时发现了codeblocks的一个问题#include#include#define MAXSIZE 100using namespace std;typedef struct activity{ int start; int end;}activity;bool compare(activity a,activity b);void greedySelector(activity act[],int n);int原创 2011-05-23 23:22:00 · 605 阅读 · 1 评论 -
词法分析器
作者:朱鑫邮箱:zhuxin@nwsuaf.edu.cn/*C语言词法分析器,从三个方面处理:关键字,运算符,界符。并且将输出,符号,常数输出到文件,可以忽略同一行的注释//-1 error,代表错误//保留字1auto 2break原创 2011-10-07 13:00:15 · 506 阅读 · 0 评论 -
getch头文件
如果你想让程序暂停一下的话,可以使用getch函数。但是,必须包含头文件原创 2011-10-23 12:27:53 · 9612 阅读 · 0 评论 -
单词转换
单词转换文件:测试文件:结果:源代码:#include#include#include#includeusing namespace std;int main(void){ ifstream file; //单词对应 ifstream test; //测试用例原创 2011-11-15 19:47:51 · 267 阅读 · 0 评论 -
c++ map简单使用
第一种方法:利用pair插入元素 #include#include#include#include using namespace std;int main(void){ map m_s_s; m_s_s.insert(pair("2009012901","朱1")); m_s_s.insert(pair("2009012902","王22")原创 2011-10-28 17:31:53 · 249 阅读 · 0 评论 -
vector的嵌套使用
#include#include#include#includeusing namespace std;typedef vector VECTOR_I;typedef map > MAP_S_S;int main(void){ VECTOR_I vec1(10,1); VECTOR_I vec2(10,2); VECTOR_I vec3原创 2011-10-28 17:54:15 · 2651 阅读 · 0 评论 -
1005 Number Sequence
#includeusing namespace std;int main(void){ int f[55]; f[1]=f[2]=1; int a,b,n; while(cin>>a>>b>>n) { if(a==0&&b==0&&n==0) { break; }原创 2011-10-30 22:47:14 · 169 阅读 · 0 评论 -
1008 Elevator
#includeusing namespace std;int main(void){ int n; int temp[100]; temp[0]=0; int sum; while(cin>>n) { if(n==0) { break; } sum=0;原创 2011-10-30 23:52:07 · 162 阅读 · 0 评论 -
const你知多少?
const关键字至少有下列n个作用:(1)欲阻止一个变量被改变,可以使用const关键字。在定义该const变量时,通常需要对它进行初始化,因为以后就没有机会再去改变它了;(2)对指针来说,可以指定指针本身为const,也可以指定指针所指的数据为const,或二者同时指定为const;(3)在一个函数声明中,const可以修饰形参,表明它是一个输入参数,在函数内部不能改变其转载 2011-11-19 12:35:41 · 209 阅读 · 0 评论 -
高质量C++/C试题答案
一、请填写BOOL , float, 指针变量 与“零值”比较的 if 语句。(10分)请写出 BOOL flag 与“零值”比较的 if 语句。(3分) 标准答案: if ( flag ) if ( !flag ) 如下写法均属不良风格,不得分。if (flag == TRUE) if (flag == 1 ) if (f转载 2011-11-19 23:16:38 · 262 阅读 · 0 评论 -
explicit简介
为了防止隐式类型转换,用explicit修饰函数即可。原创 2011-11-20 17:58:58 · 237 阅读 · 0 评论 -
怪异的switch
#includeusing namespace std;int main(void){ int n='c'; cout<<n<<endl; //99 switch(n++) { cout<<n<<endl; //忽略 d原创 2011-11-18 18:51:43 · 183 阅读 · 0 评论 -
String的构造函数、析构函数和赋值数
/*编写类String的构造函数、析构函数和赋值函数,已知类String的原理为:class String{ public: String(const char *str=NULL); String(const String &other); ~String(void); String& operator=(const String &转载 2011-11-19 12:29:19 · 278 阅读 · 0 评论 -
static你知多少?
static关键字至少有下列n个作用:(1)函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次调用时仍维持上次的值;(2)在模块内的static全局变量可以被模块内所用函数访问,但不能被模块外其它函数访问;(3)在模块内的static函数只可被这一模块内的其它函数调用,这个函数的使用范围被限制在声明它的模块内;转载 2011-11-19 12:32:20 · 258 阅读 · 0 评论 -
TR1和Boost简介
TR1(“Technical Report 1”)是一份规范,描述加入C++标准程序库的诸多新机能。这些机能以新的class templates和function templates形式体现,针对的题目有hash tables,reference-counting,smart pointers,regular expressions,以及更多。所有TR1组件都被置于命名空间tr1内,后者嵌套于命名转载 2011-11-20 18:08:15 · 774 阅读 · 0 评论 -
1004 Let the Balloon Rise
#include#include#define MAXSIZE 1001using namespace std;int main(void){ int n; map m; string temp; int number; while(1) { m.clear(); cin>>n;原创 2011-10-30 17:42:55 · 217 阅读 · 0 评论 -
杨辉三角
输出如下杨辉三角11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1#includeusing namespace std;int main(void){ int n; int a[100][100]; while(cin>>n) { for(int i=0;i<n;i++)原创 2011-11-18 18:43:53 · 196 阅读 · 0 评论 -
布尔,整形,浮点,指针与零值比较
if(bFlag)if(!bFlat)if(iValue==0)if(iValue!=0)float EPSINON=0.00001 //自定义精度if((dValue>=-EPSINON) && (dValueif(p==NULL)if(p!=NULL)转载 2011-11-19 01:48:47 · 473 阅读 · 0 评论 -
getchar你懂么?
int getchar(void);这是它的原型,既然是获得一个字符型,那为什么是整形那?因为如果读错或者结束,必须返回一个标示呀?EOF,通常是-1,。所以,它是整形。转载 2011-11-19 02:08:51 · 186 阅读 · 0 评论 -
assert你知多少?
void *memcpy(void *pvTo, const void *pvFrom, size_t size){ assert( (pvTo != NULL) && (pvFrom != NULL) ); // 使用断言 byte *pbTo = (byte *) pvTo; // 防止改变pvTo的地址 byte *pbFrom = (byte *) pvFrom; /转载 2011-11-19 12:44:26 · 186 阅读 · 0 评论 -
malloc和free原型
extern void *malloc(unsigned int num_bytes); void free(void *ptr)原创 2011-11-19 13:47:55 · 372 阅读 · 0 评论 -
strcpy函数你会么?
char *strcpy(char *strDest,const char *strSrc){ assert((strDest==NULL) && (strSrc==NULL));//判断是否为空 char *address=strDest; while((*strDest++=*strSrc++)!='\0') { ; }原创 2011-11-19 23:39:07 · 193 阅读 · 0 评论 -
1013 Digital Roots
#includeusing namespace std;int root(int n);int main(void){ string s; int sum; while(cin>>s&&s!="0") { sum=0; for(int i=0;i<s.length();i++) {原创 2011-10-31 23:13:41 · 289 阅读 · 0 评论 -
1015 Safecracker
#include#include#include#includeusing namespace std;int target;string str;int length;double a[15];bool cmp(char a,char b){ return a>b;}void solution();int main(void){原创 2011-11-01 13:39:22 · 198 阅读 · 0 评论 -
accumulate的用法
#include #include using namespace std;int main(void){ int a[] = {1, 3, 5, 7, 9}; cout << accumulate(a, a+5, 0) << endl; return 0;}原创 2011-11-21 12:56:25 · 566 阅读 · 0 评论 -
inner_productd的用法
#include #include using namespace std;string combine(const string &x, const string &y){ return "("+x+","+y+")";}string concatenate(const string &x,const string &y){ if(x.empty(原创 2011-11-21 13:01:51 · 402 阅读 · 0 评论 -
partial_sum的用法
#include #include using namespace std;int main(void){ int arr1[] = {1, 3, 9, 4} ; int arr2[4] ; partial_sum(arr1,arr1+sizeof(arr1)/sizeof(*arr1),arr2); for(int i=0;i<size原创 2011-11-21 13:04:22 · 398 阅读 · 0 评论 -
adjacent_difference的用法
#include #include using namespace std;int main(void){ int arr1[] = {1, 3, 9, 4} ; int arr2[4] ; adjacent_difference(arr1,arr1+sizeof(arr1)/sizeof(*arr1),arr2); for(int i=原创 2011-11-21 13:05:43 · 609 阅读 · 0 评论 -
min和max函数
#includeusing namespace std;bool cmp(const int &a,const int &b){ return (a > b) ;}int main(void){ int a = -999, b = 100 ; cout << min(a, b) << endl ; cout << min(a, b,原创 2011-11-21 13:13:17 · 444 阅读 · 0 评论 -
min_element和max_element
#include #include using namespace std;int main(void){ int arr[] = {1, 5, 223, 98, 4, 0, -1234}; cout << *min_element(arr,arr+sizeof(arr) / sizeof(*arr)) << endl; cout << *max_el原创 2011-11-21 13:21:33 · 262 阅读 · 0 评论 -
lexicographical_compare的用法
#include #include using namespace std;bool cmp (char c1, char c2){ return tolower(c1)<tolower(c2);}int main (void){ char first[]="Apple"; // 5 letters char second[原创 2011-11-21 13:25:30 · 672 阅读 · 0 评论 -
includes
#include #include #include using namespace std;int main (void){ int v1[]={1, 2, 3, 4, 5, 6, 7, 8, 9}; int v2[]={1, 3 ,5 ,7 ,9}; cout << boolalpha << includes(v1, v1+sizeof(v1)原创 2011-11-21 13:31:30 · 203 阅读 · 0 评论 -
set_union的用法
#include #include #include using namespace std;int main (void){ int v1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9} ; int v2[] = {100, 313 ,25 ,77 ,59} ; int v3[14] ; set_union(v1,v1原创 2011-11-21 13:36:05 · 432 阅读 · 0 评论 -
set_intersection的用法
#include #include #include using namespace std;int main (void){ int first[] = {5,10,15,20,25}; int second[] = {50,40,30,20,10}; vector v(10); vector::iterator it; so转载 2011-11-21 13:43:09 · 1600 阅读 · 0 评论 -
set_difference的用法
#include #include #include using namespace std;int main (void){ int first[] = {5,10,15,20,25}; int second[] = {50,40,30,20,10}; vector v(10); // 0 0转载 2011-11-21 13:45:28 · 1088 阅读 · 0 评论 -
set_symmetric_difference的用法
#include #include #include using namespace std;int main (void){ int first[] = {5,10,15,20,25}; int second[] = {50,40,30,20,10}; vector v(10); // 0 0转载 2011-11-21 13:47:01 · 1463 阅读 · 0 评论 -
如此easy全排列
#include #include using namespace std;int main (void){ int iArray[] = {1, 2, 3, 4, 5, 6}; sort(iArray,iArray+6); do { cout << iArray[0] << " " << iArray[1] << " " << iArray[原创 2011-11-21 13:53:22 · 189 阅读 · 0 评论 -
全排列
#include using namespace std;int total = 0;void swap(int *a, int *b){ int temp; temp = *a; *a = *b; *b = temp;}void perm(int list[], int k, int m){ if(k > m)原创 2011-11-21 14:05:11 · 198 阅读 · 0 评论 -
reverse的用法
#include #include using namespace std;int main (void){ int iArray[] = {1, 3, 3, 7, 3, 0, 0, -7, 9, 3, 10}; reverse(iArray, iArray + sizeof (iArray) / sizeof (*iArray)); for (siz原创 2011-11-21 18:09:23 · 511 阅读 · 0 评论 -
控制每行输出n个数
#include using namespace std;int main(void){ cout << "Enter two numbers:" << endl; int v1, v2; cin >> v1 >> v2; int lower, upper; if (v1 < v2) { lower = v1原创 2011-11-22 18:41:57 · 2648 阅读 · 0 评论