02 2010 档案

摘要:/*ID:tianlin2PROG:crypt1LANG:C++*/#include <iostream>#include <fstream>using namespace std;bool ina(int a[],int cou,int dit){ //注意0的情况 if(dit==0) return false; while(dit!=0) { int c=dit%10; int i; for(i=0;i!=cou;++i) { if(c==a[i]) break; } if(i==cou) return false; dit=dit/10; } return tr 阅读全文
posted @ 2010-02-25 23:04 CMuYu 阅读(151) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:calfflacLANG:C++*/#include <iostream>#include <fstream>#include <string>#include <cctype>using namespace std;//判断是不是回文,顺便算长度,不是回文长度len则返回0int iscal(char *ben,char *end){ int len=0; char *b=ben; char *e=end; while(b<e) { while(!isalpha(*b)) ++b; while(!isa 阅读全文
posted @ 2010-02-25 22:44 CMuYu 阅读(151) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:barn1LANG:C++*/#include <iostream>#include <cstdlib>#include <fstream>using namespace std;int dcmp(const void *va,const void *vb){ //注意是升序排列 return *((int *)vb)<*((int *)va)?1:-1;}int main(){ ofstream fout("barn1.out"); ifstream fin("barn1.in&quo 阅读全文
posted @ 2010-02-25 22:05 CMuYu 阅读(127) 评论(0) 推荐(0)
摘要:六类qsort排序方法前一段时间做题觉得qsort函数很好用,但有时不太会用比如按结构体一级排序、二级排序、字符串排序等,故通过查资料将其整理一番。以下是其具体分类及用法(若无具体说明是以降序排列):1、对一维数组排序:(Element_type是一位数组中存放的数据类型,可以是char, int, float, double, etc)int Comp(const void *p1,const void *p2){return *((Element_type *)p2) > *((Element_type *)p1) ? 1 : -1;}int main(){Element_type 阅读全文
posted @ 2010-02-22 10:44 CMuYu 阅读(502) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:milkLANG:C++*/#include <iostream>#include <cstdlib>#include <fstream>using namespace std;typedef struct milk milk;struct milk{ int mon; int wei;};//最大农民数milk m[5000];int moncmp(const void *va,const void *vb){ milk *a,*b; a=(milk*)va; b=(milk*)vb; if(a->mon>b 阅读全文
posted @ 2010-02-21 23:53 CMuYu 阅读(149) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:dualpalLANG:C++*/#include <iostream>#include <string>#include <fstream>using namespace std;bool ps(int n,int ary){ char a[]={'0','1','2','3','4','5','6','7','8','9'}; string b; while(n 阅读全文
posted @ 2010-02-21 19:10 CMuYu 阅读(130) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:palsquareLANG:C++*/#include <iostream>#include <string>#include <cmath>#include <fstream>using namespace std;//貌似output函数是多余的,可以直接fout<<b;void output(ofstream &fout,string b){ for(int i=b.size()-1;i>=0;--i) fout<<b[i];}void ps(int n,int m, 阅读全文
posted @ 2010-02-21 19:01 CMuYu 阅读(161) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:namenumLANG:C++*/#include <iostream>#include <string>#include <fstream>#include <cmath>using namespace std;int main(){ ofstream fout("namenum.out"); ifstream fin("namenum.in"); //m保存所对应名字的个数 long int m=0; //a保存输入的数字,c则保存字典里字符串所对应的数字,b则保存每 阅读全文
posted @ 2010-02-21 14:22 CMuYu 阅读(159) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:transformLANG:C++*/#include <iostream>#include <fstream>using namespace std;//相等bool six(char a[][11],char c[][11],int h){ int i,j; for(i=0;i!=h;++i) for(j=0;j!=h;++j) { if(a[i][j]!=c[i][j]) return false; } return true;}//90°bool one(char a[][11],char c[][11],int h 阅读全文
posted @ 2010-02-21 13:18 CMuYu 阅读(177) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:milk2LANG:C++*/#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("milk2.out"); ifstream fin("milk2.in"); int be1[5000],end1[5000]; //a为奶牛数,b为不挤奶的时间,c为最长不挤奶的时间,x为至少一个人挤奶的时间,y为最长挤奶时间 int a,b=0,c=0,x=0,y=0; fin>>a; 阅读全文
posted @ 2010-02-21 12:56 CMuYu 阅读(189) 评论(0) 推荐(0)
摘要:复杂度为O(n2):#include <stdio.h>#include <string.h>#include <assert.h>#define MAXN 400char necklace[MAXN];int len;/* * Return n mod m. The C % operator is not enough because * its behavior is undefined on negative numbers. *///这种处理 转一圈回到头 的情况很值得学习int mod(int n, int m){ while(n < 0) 阅读全文
posted @ 2010-02-21 11:50 CMuYu 阅读(152) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:beadsLANG:C++*/#include <iostream>#include <fstream>using namespace std;//若函数里要改变变量的值,需引用bool eq(char &x,char &y){ if(x=='w'&&y=='b') return true; if(x=='b'&&y=='w') //注意函数里数据的变换 { y=x; return true; } if(x=='w& 阅读全文
posted @ 2010-02-21 10:23 CMuYu 阅读(130) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:fridayLANG:C++*/#include <iostream>#include <fstream>using namespace std;bool runian(int year) //判断是不是闰年{ if(year%400==0||year%4==0&&year%100!=0) return true; else return false;}int main(){ ofstream fout("friday.out"); ifstream fin("friday.in" 阅读全文
posted @ 2010-02-20 18:51 CMuYu 阅读(157) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:gift1LANG:C++*/#include <iostream>#include <string>#include <fstream>using namespace std;int main(){ ofstream fout("gift1.out"); ifstream fin("gift1.in"); int mo,ge; int a,b=0,c=0; string s1,s2; fin>>a; string *st=new string[a]; int *mon= 阅读全文
posted @ 2010-02-20 15:02 CMuYu 阅读(167) 评论(0) 推荐(0)
摘要:/*ID:tianlin2PROG:rideLANG:C++*/#include <iostream>#include <string>#include <fstream>using namespace std;int main(){ string a,b; ofstream fout("ride.out"); ifstream fin("ride.in"); int c=1,d=1; fin>>a>>b; for(string::size_type i=0;i!=a.size();++i) { 阅读全文
posted @ 2010-02-20 13:41 CMuYu 阅读(146) 评论(0) 推荐(0)