//iotool.c
#include <stdio.h> int inputInt(const char *info) { int r; printf("%s:",info); scanf("%d",&r); return r; }
graphic.c
//iotool.c
#include <stdio.h> int inputInt(const char *info) { int r; printf("%s:",info); scanf("%d",&r); return r; }
graphic.c
code:
class Program { static void Main(string[] args) { try { replacefile rf = new replacefile(); rf.doReplace(@"F:\c1"); rf.doReplace(@"F:\c2"); rf.doReplace(@"F:\c3"); Console.WriteLine("替换完成!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } public class replacefile { public string sourceFilejs = @"F:\frmleftdown.js";//源文件 public string sourceFilexml = @"F:\frmleftdown.xml";//源文件 public void doReplace(string parentPath) { string[] files = Directory.GetFiles(parentPath); foreach (string f in files) { if (f=="frmleftdown.js") File.Copy(sourceFilejs, f, true);//替换目录下所有的同名文件 if (f=="frmleftdown.xml") File.Copy(sourceFilexml, f, true); } string[] subdirs = Directory.GetDirectories(parentPath); foreach (string subdir in subdirs) { doReplace(subdir); } } }
iterator.cpp
/* 迭代器 输入:可读,不一定可改值 输出:可改,不一定可读值 前向:可读可改 双向:支持 -- 随机:支持--、+n、-n、下标访问 */ #include<iterator> #include<iostream> using namespace std; #include<algorithm> #include<vector> #include "print.h" #include<fstream> int main() { //输入迭代 istream_iterator<int> in(cin);//输入流cin,也可以是文件输入流 istream_iterator<int> end; vector<int> vi; copy(in,end,back_inserter(vi));//一直输入,按ctrl+D结束 print(vi.begin(),vi.end()); //输出迭代 ofstream fo("out.txt"); ostream_iterator<int> o(cout,","); ostream_iterator<int> ofile(fo," "); copy(vi.begin(),vi.end(),o); copy(vi.begin(),vi.end(),ofile); fo.close(); cout<<endl; }
//specialcontainer.cpp
/*一般容器:stack,queue 特殊容器:priority_queue .push(element),.pop(),.empty() stack:.top() queue:.front(),.back() priority_queue:.top() 没有迭代器 */ #include<iostream> #include<queue> using namespace std; int main() { priority_queue<int> pq; pq.push(40); pq.push(20); pq.push(10); pq.push(50); pq.push(90); while(!pq.empty()) { cout<<pq.top()<<' '; pq.pop(); } cout<<endl; return 0; }
print.h
//print.h #include <iostream> using namespace std; #ifndef print_fun #define print_fun template<typename T> ///显示序列数据 void print(T b,T e,char c=' ') { bool isExit=false; while (b!=e) { cout<<*b++<<c; isExit=true; } if(isExit) cout<<endl; } template<typename K,typename V> ostream& operator<<(ostream& o,const pair<K,V>& p)//重载输出map类型元素 { return o<<p.first<<':'<<p.second; } #endif
//js弹出固定大小窗口
<SCRIPT language=javascript> function openScript(url, width, height) { var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=n0' ); } </SCRIPT>
<body> <a href='javascript:openScript("http://www.baidu.com",300,400)' >1234324</> </body>
multimap.cpp
/* multimap特性 key可以重复 不支持下标访问 */ #include<iostream> #include<string> #include "print.h" #include<map> using namespace std; typedef pair<int,string> pairmp; typedef multimap<string,double> MS; int main() { MS m; m.insert(MS::value_type("t1",1000)); m.insert(MS::value_type("t1",1300)); m.insert(make_pair("t2",3000)); m.insert(MS::value_type("t1",1800)); m.insert(make_pair("t2",100000)); m.insert(MS::value_type("t1",1600)); print(m.begin(),m.end()); MS::iterator ib=m.begin(),ie; MS m2; while(ib!=m.end()) { string name=ib->first;//first:K,second:V ie=m.upper_bound(name);//同一个key的一个区别上界 double sum=0.0; while(ib!=ie) { sum+=(ib++)->second; } m2.insert(make_pair(name,sum));//处理,并加入一个容量 } print(m2.begin(),m2.end()); return 0; }
map.cpp
/* map.cpp map特性 不允许key重复 key/value对 key可以当下标访问value,key不存在则插入新的key/value对,以0初始化 */ #include<iostream> #include<string> #include "print.h" #include<map> using namespace std; typedef pair<int,string> pairmp; #include<map> int main() { map<int,string> mp; mp.insert(pair<int,string>(1,"aaa")); mp.insert(make_pair(5,"bbb"));//自动匹配类型,构造pair mp.insert(map<int,string>::value_type(4,"fff"));//内部类型,也能自动构造相应的pair mp.insert(make_pair(2,"hhh")); mp.insert(make_pair(2,"hhh")); mp[2]="hhh1";//有则修改 mp[3]="ddd";//无则插入 print(mp.begin(),mp.end()); return 0; }
code:
/* 关联式容器共性:二叉查找树实现,自动根据关键字排序,自动平衡 set<K>,multiset<K>,map<K,V>,multimap<K,V> 查找:.find(key) 失败返回.end() 统计:.count(key) 删除:.erase(key) 插入:.insert(element) 区间:.lower_bund(key) //取得关键字为key的第一个元素位置 .upper_bound(key) //取得关键字为key的最后一个元素之后的位置 .equal_range(key) 取得关键字为key的区间,返回pair 构造函数可用比较函数作为参数 bool func(K a,K b) */ #include<iostream> #include<set> #include<string> using namespace std; #include "print.h" struct person { string name; int age; public: person(const char* n,int a):name(n),age(a){} }; bool operator<(const person& a,const person& b) { return a.age<b.age||(a.age==b.age&& a.name<b.name);//找的时候按这个找 } ostream& operator<<(ostream& o,const person& x) { return o<<x.name<<':'<<x.age<<" "; } int main() { multiset<person> mp; mp.insert(person("ccc",16)); mp.insert(person("aaa",13)); mp.insert(person("aaa",13)); mp.insert(person("kkk",18)); mp.insert(person("fff",15)); mp.insert(person("eee",11)); mp.insert(person("jjj",16)); print(mp.begin(),mp.end()); multiset<person>::iterator it=mp.find(person("fff",15)); if(it==mp.end()) cout<<"not find!\n"; else { cout<<"find:"<<*it <<" "<<mp.count(*it)<<"个\n"; } person a("aaa",13); cout<<a<<" "<<mp.count(a)<<"个\n"; cout<<"lower/upper bound方法:\n"; multiset<person>::iterator ibegin,iend; ibegin=mp.lower_bound(a); iend=mp.upper_bound(a); print(ibegin,iend); cout<<"pair方法:\n"; typedef multiset<person>::iterator myiter;//给长类型起个别名 pair<myiter,myiter> p=mp.equal_range(a); print(p.first,p.second); cout<<"删除后输出:\n"; mp.erase(person("kkk",18));//有多个就删除多个 print(mp.begin(),mp.end()); }