02 2014 档案

摘要:在构造文件流变量时候发现,fstream的第一个参数,即文件路径必须是const char *如:1 string s = "/home/user/1.txt";2 fstream file (s,ios::in);编译是不能通过的,必须将文件的路径改为const char *才可以。以下是三种转化方法:1 string str="abc";2 char *p=str.data();1 string str="gdfd";2 char *p=str.c_str();1 string str="hello";2 ch 阅读全文
posted @ 2014-02-21 11:15 轻度YYy 阅读(7073) 评论(0) 推荐(1)
摘要:代码中在第一层循环中增加一个bool值,是为了防止在排序完成后还继续无谓的比较,最多会有(n-1)*(n-2)/2次循环。 1 #include 2 using namespace std; 3 void bumbleSort(int a[],int l) 4 { 5 for(int i = 0;ia[j+1])13 {14 if(b)15 b = false;16 int temp = a[j];17 a[j] = a[j+1];18 a[j+1] = temp;19 }20 21 }22 ... 阅读全文
posted @ 2014-02-20 15:09 轻度YYy 阅读(239) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 int partition(int a[],int p,int q){ 4 int x = a[q]; 5 int i = p-1; 6 for(int j = p;j<q;j++) 7 { 8 if(a[j]<x) 9 {10 i++;11 int temp = a[j];12 a[j] = a[i];13 a[i] = temp;14 }15 }16 a[q]=a[i+1];17 a[i+1]=x;18 return i+1;19 }20 void qsort(int a[],int p,int q){21 阅读全文
posted @ 2014-02-20 13:35 轻度YYy 阅读(178) 评论(0) 推荐(0)
摘要:其实把程序用到生活中,真的能节约不少时间!程序的力量是无穷滴!哥们的毕业设计是要做法律文书匹配之类的东东,有一步是要抽取所有的法律法规名称,而刚好我们要处理的文件中,法规的名称之前都有个‘.‘,所以用下面的代码处理很方便。以下分别是处理前后的文件格式:只有十几行的代码 1 #include 2 #include 3 #include 4 using namespace std; 5 int main(){ 6 fstream f("1.txt",ios::in|ios::out); 7 fstream ff("3.txt",ios::out); 8 st 阅读全文
posted @ 2014-02-20 11:08 轻度YYy 阅读(297) 评论(0) 推荐(0)
摘要:使用PPA(Personal Package Archive)在ubuntu上安装emacs1添加 PPA 到 apt repository 中: $ sudo add-apt-repository ppa:cassou/emacs $ sudo apt-get update2然后,可以使用apt-get方便地下载Emacs $ sudo apt-get install emacs24 emacs24-el emacs24-common-non-dfsg 阅读全文
posted @ 2014-02-08 22:13 轻度YYy 阅读(452) 评论(0) 推荐(0)