摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 4 /* 5 值传递,地址传递,引用传递 6 */ 7 void find1(char array[], char search, char **pa) 8 { 9 //等价于, array = str, search = p, pa = &pc; 10 11 **pa = 'c';12 13 }14 15 int main( )16 {17 char str[1000], p[1000];18 while( scanf("%s%s",&
阅读全文
摘要:1.语言中变量的实质要理解C指针,我认为一定要理解C中“变量”的存储实质, 所以我就从“变量”这个东西开始讲起吧!先来理解理解内存空间吧!请看下图:内存地址→ 6 7 8 9 10 11 12 13-----------------------------------------------------------------。。。 | | | | | | | |.。------------------------------- ----------------------------------如图所示,...
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<time.h>#include<map>#include<set>#include<algorithm>using namespace std;pair<int,int>p[1000];int mai
阅读全文
摘要:View Code // multimap::lower_bound/upper_bound#include <iostream>#include <map>using namespace std;int main (){ multimap<char,int> mymultimap; multimap<char,int>::iterator it,itlow,itup; mymultimap.insert(pair<char,int>('a',10)); mymultimap.insert(pair<char,i
阅读全文
摘要:算法:1.map 985ms..2.Trie树,250ms..4倍。。3.排序+二分查找 200ms左右struct dict{ char a[11]; char b[11];}dic[100001];4. HASH将字符串映射为一个HASH值,HASH函数可以从网上自己找一个用静态链表处理冲突,速度最快235msView Code /*代码自己没写了,此代码来自http://wingszero.blogbus.com/logs/60733344.html*/#include<iostream>#include<string>using namespace std;co
阅读全文
摘要:View Code #include <iostream>#include <string>#include <cstdlib>using namespace std;class student{ public: student( ) { name = "tang"; num = "104080219"; sex = "M"; } void display( ); void input( ); private: string name; string num; string sex;};class
阅读全文
摘要:View Code /*运算符重载,类型转换函数,转换构造函数无参默认构造函数,带参初始化构造函数,*/#include <iostream.h>//#include <iostream>#include <cstdlib>//using namespace std;class Complex{ public: Complex( ) { real = 0; imag = 0; } //无参默认构造函数 //Complex(double r) { real = r; imag = 0;} 转换构造函数 Complex(double r, double i) {
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int str[11000];int main( ){ int N, M, i, j; while ( scanf("%d%d", &N, &M) != EOF) { for ( i = 1; i <= N; i++) str[i-1] = i; //默认已经是第1小了 int num = 0; while( num
阅读全文
摘要:What Are You Talking AboutTime Limit: 10000/5000 MS (Java/Others)Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 4522Accepted Submission(s): 1366Problem DescriptionIgnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>int main( ){ int dp[10000]; int N, i, j, num, t; while (scanf("%d", &N) != EOF ) { num = 0; for (i = 0; i < N; i++) scanf("%d",&dp[i]); for (i = 0; i < N; i++) { if (dp[i] != -1) { t = dp[i],
阅读全文
摘要:// greater example#include <iostream>#include <functional>#include <algorithm>using namespace std;int main () { int numbers[]={20,40,50,10,30}; sort (numbers, numbers+5, greater<int>() ); for (int i=0; i<5; i++) cout << numbers[i] << " "; cout <<
阅读全文
摘要:// distance example#include <iostream>#include <iterator>#include <list>using namespace std;int main () { list<int> mylist; for (int i=0; i<10; i++) mylist.push_back (i*10); list<int>::iterator first = mylist.begin(); list<int>::iterator last = mylist.end(); co
阅读全文
摘要:advance example#include <iostream>#include <iterator>#include <list>using namespace std;int main () { list<int> mylist; for (int i=0; i<10; i++) mylist.push_back (i*10); list<int>::iterator it = mylist.begin(); advance (it,5); cout << "The sixth element in
阅读全文
摘要:// priority_queue::push/pop#include <iostream>#include <queue>using namespace std;int main (){ priority_queue<int> mypq; mypq.push(30); mypq.push(100); mypq.push(25); mypq.push(40); cout << "Popping out elements..."; while (!mypq.empty()) { cout << " &quo
阅读全文
摘要:// remove algorithm example#include <iostream>#include <algorithm>using namespace std;int main () { int myints[] = {10,20,30,30,20,10,10,20}; // 10 20 30 30 20 10 10 20 // bounds of range: int* pbegin = myints; // ^ int* pend = myints+sizeof(myints)/sizeof(int); // ^ ^ pend = remove (pbe
阅读全文
摘要:// remove_if example#include <iostream>#include <algorithm>using namespace std;bool IsOdd (int i) { return ((i%2)==1); }int main () { int myints[] = {1,2,3,4,5,6,7,8,9}; // 1 2 3 4 5 6 7 8 9 // bounds of range: int* pbegin = myints; // ^ int* pend = myints+sizeof(myints)/sizeof(int); //
阅读全文
摘要:// reverse algorithm example#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () { vector<int> myvector; vector<int>::iterator it; // set some values: for (int i=1; i<10; ++i) myvector.push_back(i); // 1 2 3 4 5 6 7 8 9 reverse(myve
阅读全文
摘要:// find_if example#include <iostream>#include <algorithm>#include <vector>using namespace std;bool IsOdd (int i) { return ((i%2)==1);}int main () { vector<int> myvector; vector<int>::iterator it; myvector.push_back(10); myvector.push_back(25); myvector.push_back(40); my
阅读全文
摘要://通用算法stable_partition的作用是将容器中符合表达式条件的元素全都排列到容器的前半部,并返回最后一个符合项的迭代器地址// stable_partition example#include <iostream>#include <algorithm>#include <vector>using namespace std;bool IsOdd (int i) { return (i%2)==1; }int main () { vector<int> myvector; vector<int>::iterator it
阅读全文
摘要:// equal algorithm example#include <iostream>#include <algorithm>#include <vector>using namespace std;bool mypredicate (int i, int j) { return (i==j);}int main () { int myints[] = {20,40,60,80,100}; // myints: 20 40 60 80 100 vector<int>myvector (myints,myints+5); // myvector
阅读全文