摘要:
简单模拟:CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<stack>#include<ctype.h>#definemin2000#definemax10000usingnamespacestd;constintmaxn=101;chars1[maxn],s2[maxn];inttot1,tot2;intinit(intx)//计算一个数的树根之和{intsum=0;while(x){sum+=x% 阅读全文
摘要:
简单模拟。CODE:#include<stdio.h>#include<string.h>#include<stdlib.h>usingnamespacestd;constintmaxn=101;chars[maxn][maxn];intmain(){intc;intcnt;charstr[201];while(~scanf("%d",&c),c){inti,j;scanf("%s",str);intl=strlen(str)/c;cnt=0;for(i=0;i<l;i++){if(i%2==0){for 阅读全文
摘要:
简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;inta[16];intcmp(constvoid*a,constvoid*b){return*(int*)a-*(int*)b;}intmain(){intn;inttot=0,sum=0;while(scanf("%d",&n)){inti,j;if(n==-1)break;if(n){a[tot++]=n;}else{qsort(a,tot,sizeof(int), 阅读全文
摘要:
思路:异或运算的运用,破译密码时一定存在一个大写字母使得所有的原文在'A'~'Z'之内。异或运算法则: 1. a ^ b = b ^ a 2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c; 3. d = a ^ b ^ c 可以推出 a = d ^ b ^ c. 4. a ^ b ^ a = b. 相关链接(http://acm.hdu.edu.cn/showproblem.php?pid=1287)CODE:#include<stdio.h>#include<stdlib.h>#include<st 阅读全文
摘要:
思路:首先看能兑换多少个三分硬币的,然后当三分硬币分别为1,2,3,.... n时有多少个2分硬币的,为什么要这样确定了?因为只要还可以兑换出三分硬币和二分硬币的那么剩下的价值一定可以让价值为1的硬币塞满。开头为什么s为N/3+1呢?因为可以这样想,假设N=7,那么只包含3分硬币和1分硬币的组合方式为:3,3,1; 3,1,1,1,1;所以N/3是实际上可以容纳三分硬币的个数。而增加1是因为可以全部换成1分的硬币。有人会疑问,那么t = (N-3*i)/2不是会重复吗?这是不可能的,因为硬币的价值是递增的,只有当i的值为N/3时,t的值可以为0或者1。所以不会重复。CODE:#include& 阅读全文
摘要:
简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=101;chars[maxn];intnum[2000],cnt;intis_hw(intx)//是否是回文数{inti;sprintf(s,"%d",x);intl=strlen(s);intok=1;for(i=0;i<l;i++){if(s[i]!=s[l-i-1]){ok=0;break;}}if(ok)return1;return0;}i 阅读全文