- 博客(22)
- 收藏
- 关注
原创 二叉树四种遍历(非递归)
#include#includeusing namespace std;struct Node{ char val; Node *left; Node *right;};struct cheryl{ Node *n; char tag;};typedef Node* node;node insert(Node *root,char ch);vector cenxu(No
2015-04-24 09:11:19
514
原创 leetcode #102Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20
2015-04-22 19:40:19
419
原创 leetcode #1 two sum
#include#include#include#includeusing namespace std;class Solution {public: static bool cmp(pair &p1,pair &p2){ return p1.first<p2.first;} vector twoSum(vector &numbers, int target) { v
2015-04-16 20:17:46
369
原创 (看了别人的idea)1040. 有几个PAT(25)
这道题想死想不出,于是百度了,看了别人的想法之后,只能说太巧妙了。作为新手程序员的我还需要更加努力啊!!!!!!!#include#includeint main(void){ using namespace std; string str; unsigned num_t=0; unsigned num_at=0; unsigned num_pat=0; cin>>str; fo
2015-04-07 18:43:44
812
原创 1030. 完美数列(25)
#include#include#includeint main(void){ using namespace std; int n,m; double p; double a[100000]; scanf("%d%lf",&n,&p); for(m=0;m<n;++m){ scanf("%lf",&a[m]); } sort(a,a+n); int max=0; f
2015-04-06 15:32:44
400
原创 1025. 反转链表 (25)
#include#include#include#includeint main(void){ using namespace std; map m1; map m2; int first_add; int n; int i; cin>>first_add>>n>>i; int nn=n; while(nn){ int address; int num;
2015-04-06 14:55:20
405
原创 PAT(BASIC)1033. 旧键盘打字(20)
#include#include#includeint main(void){using namespace std;int hasher[255]={0};char c;while((c=getchar()) && (c!='\n')){if(c=='+'){for(char t = 'A';t hasher[t]=1;}else if(isupp
2015-04-05 15:14:11
465
原创 PAT(BASIC)1029. 旧键盘(20)
#include#include#include#includeint main(void){ using namespace std; string str1,str2; cin>>str1>>str2; for(auto &c:str1){ if(islower(c)) c=toupper(c); } for(auto &c:str2){ if(islow
2015-04-05 14:42:34
473
原创 PAT(BASIC)1015. 德才论 (25)
//用cout老是运行超时,改用c风格的printf就可以了#include#include#include#include#includeusing namespace std;struct data{ unsigned id; unsigned de; unsigned cai; unsigned sum;};bool comp(data d1,data d2){
2015-04-05 11:26:06
449
原创 PAT(BASIC)1028. 人口普查(20)
其实一次便利就行了的,不过懒,懒得改,写的实在太麻烦了,还好通过了- -#include#include#includeusing namespace std;struct data{ string name; unsigned yy; unsigned mm; unsigned dd;};int main(void){ int n; int avail=0; cin>>
2015-04-05 10:38:19
750
原创 PAT(BASIC)1005 继续3n+1猜想
#include#include#include#includeusing namespace std;vector re_vector(int i);int main(void){ int n; cin>>n; vector> sum; int temp; while(n){ bool tag=false; cin>>temp; for(auto out:sum
2015-04-04 17:16:17
465
原创 PAT(BASIC)1037. 在霍格沃茨找零钱(20)
代码确实有点冗长,请见谅。#includestruct money{ int Galleon; int Sickle; int Kunt;};int main(void){ using namespace std; money should_pay,pay,resault; char c; cin>>should_pay.Galleon>>c>>should_pay.Sickl
2015-04-04 10:59:56
1332
1
原创 PAT(BASIC)1039. 到底买不买(20)
#include#include#includeint main(void){ using namespace std; string str_solder,str_buyer; map solder; map buyer; cin>>str_solder>>str_buyer; for(auto c:str_solder) ++solder[c]; for(auto c:
2015-04-04 09:56:21
862
原创 c++primer练习11.33
//实现你自己版本的单词转换程序#include#include#include#includeusing namespace std;void my_word_transform(ifstream &map_file,ifstream &input);map my_build_map(ifstream &map_file);const string& my_transform(c
2015-04-03 21:03:00
404
原创 c++prime 练习 11.12
/*编写程序,读入string和int序列,将每个string和int存入一个pair中,pair保存在一个vector中。*/#include#include#include#include#includeint main(int argc,char *argv[]){ using namespace std; ifstream in1(argv[1]),in2(argv[2])
2015-04-03 15:51:34
539
原创 c++primer 练习11.9
/*11.9定义一个map,一个行号的list关联,list中保存的是单词出现的行号*/#include#include#include#include#include#include#includeusing namespace std;void change(string &str){ if(isupper(str[0])) str[0]=tolower(str[
2015-04-03 14:31:08
509
原创 c++primer练习10.18
重写biggies,用partition代替find_if。#include#include#include#include#includeusing namespace std;void biggies(vector &s,vector::size_type sz);void elimdups(vector &s){ sort(s.begin(),s.end()); auto
2015-03-21 20:54:03
446
原创 c++primer练习10.15
Q:编写一个lambda,捕获它所在函数的int,并接受一个int参数。lambda应该返回捕获的int和int参数的和。#includeusing namespace std;int sum(const int &i,const int &j){ auto foo=[i](int j){return i+j;}; return foo(j);}int main(void){ co
2015-03-21 20:13:05
358
原创 c++primer练习10.14
编写一个lambda,接受两个Int,返回他们的和。#includeint main(void){ using namespace std; auto sum=[](int i,int j){return i+j;}; cout<<sum(1,1)<<endl; return 0;}
2015-03-21 19:56:00
447
原创 c++primer练习10.13
#include#include#include#include#includeusing namespace std;void elimdups(vector &s);bool bigger_five(const string &s){return s.size()>=5;}int main(void){ char *p[]={"indicate","apple","red",
2015-03-21 19:39:46
499
原创 c++primer练习10.11
Q:编写程序,使用stable_sort和isshorter将传递给你的elimdups版本的vector排序。打印vector的内容,验证你的程序的正确性。#include#include#include#include#includeusing namespace std;void elimdups(vector &s);bool isshorter(const string &
2015-03-21 19:23:53
476
原创 c++primer练习10.9
实现你自己的elimdups。测试你的程序,分别在读取输入后、调用unique后以及调用erase后打印vector的内容。#include#include#include#include#includeusing namespace std;void elimdups(vector &s);int main(void){ char *p[]={"indicate","appl
2015-03-21 19:14:32
518
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人