上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 30 下一页
  2012年7月20日
摘要: 简单模拟。注意结构体的二级排序以及字符串的排序。由于排序函数中间的n与N混淆,贡献了many WA。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;intscore[15];constintSIZE=1010;structstu{chars[21];intgrade;}a[SIZE];intcmp(constvoid*a,constvoid*b){stu*p1=(stu*)a;stu*p2=(stu*)b; 阅读全文
posted @ 2012-07-20 20:57 有间博客 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 第一次只直接枚举写的,效率比较低。由于知道网上一定有更好的方法,所以去参考了别人的代码。所以第二次是用hash写的。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=1001;inta[1001];intsearch(int*a,intn,intv){inttot=0;for(inti=0;i<n;i++){if(a[i]==v)tot++;}returntot;}intmain(){intn;while(~scanf(&qu 阅读全文
posted @ 2012-07-20 17:11 有间博客 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 简单字符串排序问题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;constintSIZE=101;structindex{charstr[16];intbeg,end;}a[SIZE];intcmp1(constvoid*a,constvoid*b){index*p1=(index*)a;index*p2=(index*)b;returnp1->beg>p2->beg?1:-1;}in 阅读全文
posted @ 2012-07-20 16:46 有间博客 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 基础DP。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=10001;inta[maxn];intbeg,end;//开始,结束intget_max(int*a,intn)//算法复杂度为O(n){inti,j;beg=end=0;intMaxSum=0,ThisSum=0,index=0;intcnt=0,pos=0;for(i=0;i<n;i++){ThisSum+=a[i];if(a[i]<0)cnt++;//记 阅读全文
posted @ 2012-07-20 13:52 有间博客 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。代码有点乱,感觉自己实现起来也有点麻烦。要加大力度练习啦!~CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=101;charstr[11][20]={"zero","one","two","three","four","five","six","seven",& 阅读全文
posted @ 2012-07-20 12:36 有间博客 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>usingnamespacestd;constintmaxn=101;chars[maxn];inta[maxn];intget(char*s,int*a){intl=strlen(s);inttot=0,i=0,num=0;while(i<l){for(;i<l&&isdigit(s[i]);i++){num=num*10+s[i]-'0'; 阅读全文
posted @ 2012-07-20 10:00 有间博客 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题,主要是库函数的使用。fets(s, maxn, stdin);它使用时是一行一行的读入,且读取最大的字符数为maxn-1;最后补'\0',一旦遇到回车符'\n‘读取工作就会停止。这'\n'是该数组最后一个有效字符,再往后就是'\0'了。CODE:#include<stdio.h>#include<stdlib.h>#include<ctype.h>#include<string.h>usingnamespacestd;constintmaxn=1001;chars[maxn];i 阅读全文
posted @ 2012-07-20 09:19 有间博客 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。求中位数CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;constintmaxn=10001;inta[maxn];intcmp(inta,intb){returna<b;}intmain(){intn;while(~scanf("%d",&n)){inti;for(i=0;i<n;i++)scanf("%d",&a[i]);s 阅读全文
posted @ 2012-07-20 09:03 有间博客 阅读(116) 评论(0) 推荐(0) 编辑
  2012年7月18日
摘要: 简单模拟题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;intcheck(inta,intb,intk){inti,j;intsum1=0,sum2=0;for(i=0;i<k;i++){intx=a%10;inty=b%10;if(x!=y){return0;}else{sum1+=x;sum2+=y;a/=10;b/=10;}}if(sum1==sum2)return1;}intmain(){inta,b,k;while(~scanf(&qu 阅读全文
posted @ 2012-07-18 22:18 有间博客 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。找规律,只要最大的那个数max-(s-max)<=1即可全部吃完。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;constintmaxn=1000001;inta[maxn];intmain(){intT;intn;__int64s;//定义为__int64,要不会WAscanf("%d",&T);while(T--){inti;s=0;__int64max=-1; 阅读全文
posted @ 2012-07-18 21:30 有间博客 阅读(110) 评论(0) 推荐(0) 编辑
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 30 下一页