随笔分类 - HDOJ
摘要:0^0 =00^1=11^0=11^1=0可以发现 任何数异或0还是他本身。一个数异或另一个数偶数次还是他本身。#include <stdio.h>int main(){ int i;int num,n,ans; while(scanf("%d",&n),n){ ans=0; for(i=0;i<n;++i){ scanf("%d",&num); ans^=num; } printf("%d\n",ans); } return 0;}
阅读全文
posted @ 2012-06-24 13:50
加拿大小哥哥
摘要://中间不算停留时间,就是如果序列中相邻两个楼层相同的话,电梯还是会停留5秒 #include <stdio.h>int main(){ int i,n,a[101],sum; while(scanf("%d",&n),n) { sum=0; a[0]=0; for(i=1;i<=n;i++) scanf("%d",a+i); for(i=0;i<n;i++) { if(a[i]<=a[i+1]) //!!小于等于{ sum+=(a[i+1]-a[i])*6+5; } else if(a[i]>a[i+1])
阅读全文
posted @ 2012-05-30 20:25
加拿大小哥哥
摘要:/*虽然是简单题,但也wa了好多次,就因为那个flag*/#include<stdio.h>int main(){ int i,j,T,flag;int a[100]; float ans; scanf("%d",&T); for(i=0;i<T;i++) scanf("%d",a+i); for(i=0;i<T;i++) { ans=0.00; flag=1; for(j=0;j<a[i];j++) { ans+=1.0/(j+1)*(flag); flag=-flag;/*不是flag=-1*/ } printf
阅读全文
posted @ 2012-05-26 10:56
加拿大小哥哥
摘要:#include<stdio.h>#include<string.h>typedef struct//二维数组没有这个方便{ char str[16]; int num;}Node;int main(){ Node col[1001]; int T,i,j,max; while(~scanf("%d",&T),T) { getchar(); for(i=1;i<=T;i++) col[i].num=0; for(i=1;i<=T;i++) { scanf("%...
阅读全文
posted @ 2012-05-14 23:19
加拿大小哥哥
摘要:Problem Description妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐。现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵。Input输入含有一些数据组,每组数据包括菜种(字串),数量(计量单位不论,一律为double型数)和单价(double型数,表示人民币元数),因此,每组数据的菜价就是数量乘上单价啊。菜种、数量和单价之间都有空格隔开的。Output支付菜价的时候,由于最小支付单位是角,所以总是在支付的时候采用四舍五入的方法把分头去掉。最后,请输出一个精度为角的菜价总量。Sample Input青菜 1 2罗卜 2 1.5鸡..
阅读全文
posted @ 2012-05-14 23:10
加拿大小哥哥
摘要:#include<stdio.h>#include<math.h>int main(){ int a,b,k,s; while(~scanf("%d%d%d",&a,&b,&k),a||b) { s=1; while(k--) s*=10; //printf("%d\n",s); if (a%s==b%s) printf("-1\n"); else printf("%d\n", a+b); } return 0;} 下面都是wa#include<stdio.h&
阅读全文
posted @ 2012-05-14 12:49
加拿大小哥哥
摘要:#include <stdio.h>double Factorical(int n){ int ans=1;int i; double sum=1.0; for(i=1;i<=n;++i) { ans=ans*i; sum+=(double)1/ans; } return sum;}int main(){ int i; printf("n e\n"); printf("- -----------\n") ; for(i=0;i<10;i++) { if(i==0) ...
阅读全文
posted @ 2012-04-24 07:30
加拿大小哥哥
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int f[200],a,b,n,i; 5 while(scanf("%d%d%d",&a,&b,&n),a||b||n) 6 { 7 if(n>2) 8 { 9 f[1]=f[2]=1;10 for(i=3;i<200;i++)11 {12 f[i]=(a*f[i-1]+b*f[i-2])%7;13 if(f[i-1]==1...
阅读全文
posted @ 2012-04-22 15:43
加拿大小哥哥
摘要:#include<stdio.h>#include<string.h>typedef struct//二维数组没有这个方便{ char str[16]; int num;}Node;int main(){ Node col[1001]; int T,i,j,max; while(~scanf("%d",&T),T) { getchar(); for(i=1;i<=T;i++) col[i].num=0; for(i=1;i<=T;i++) { scanf("%...
阅读全文
posted @ 2012-04-22 12:47
加拿大小哥哥
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>int cmp(const void *a,const void *b){return strcmp((char *)a,(char *)b);}int main(){char str[4];while(~scanf("%s",str)){//fflush(stdin);qsort(str,3,sizeof(char),cmp);printf("%c %c %c\n",str[0],str[1],str[2]);}
阅读全文
posted @ 2012-04-21 20:51
加拿大小哥哥
摘要://wa的代码,既然说是整数,应该不用考虑大数,可实际上却要考虑大数#include<stdio.h>int main(){int num,temp;while(scanf("%d",&num),num){temp=num%9;printf("%d\n",temp);}return 0;}//或者mod9,若是k,则各个数字和为k//既然说是整数,应该不用考虑大数,可实际上却要考虑大数/*超时代码#include<stdio.h>int count_digit(int num){int sum=0,p=1;while(p)
阅读全文
posted @ 2012-04-21 18:40
加拿大小哥哥
摘要:1.log10(num)+12.较小数情况下,sprintf(str,"%d",num);输出strlen(str),所以不能初始化为0自然对数:log() ,以二为底log2(num)=log(num)/log2,因为那个自然对数的底是无理数,不好表示,只要有了自然对数的表示,其他用换底公式就OK啦我一直想的是求出阶乘后,再strlen(str),其实求阶乘位数有一个公式//lnN!=NlogN-N+0.5*log(2*PI*N)#include<stdio.h>#include<math.h>#define PI 3.14159265int nu
阅读全文
posted @ 2012-04-21 14:53
加拿大小哥哥
摘要:1.scanf(“ %s%s”,str1,str2),在多个字符串之间用一个或多个空格分隔;若使用gets函数,应为gets(str1); gets(str2); 字符串之间用回车符作分隔。通常情况下,接受短字符用scanf函数,接受长字符用gets函数。而getchar函数每次只接受一个字符,经常c=getchar()这样来使用。2.#include<stdio.h>#include<string.h>int main(){char s[202];int i;while(gets(s))//gets后面不用加getchar了{if(strcmp(s,"ST
阅读全文
posted @ 2012-04-21 13:15
加拿大小哥哥
摘要:Problem Descriptionwe define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;Give you a letter x and a number y , you should output the result of y+f(x).InputOn the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.O
阅读全文
posted @ 2012-04-20 22:31
加拿大小哥哥
摘要:#include<stdio.h>#include<string.h>intmain(){voidd(char*s);char*pa,*pb,a[100000],b[100000];while(scanf("%s%s",&a,&b)!=EOF){pa=a; pb=b;while(*pa=='0'){pa++;}while(*pb=='0'){ pb++;}d(pa);d(pb);printf(strcmp(pa,pb)?"NO\n":"YES\n");}retur
阅读全文
posted @ 2012-04-19 22:24
加拿大小哥哥
摘要:#include<stdio.h>int main(){ int sum,temp;int t,i; while(~scanf("%d",&t)) { sum=0; for(i=1;i<=t;i++) { scanf("%d",&temp); sum+=temp; } printf("%d\n",sum); } return 0;}//超时代码#include<stdio.h>int main(){ int sum,temp;int t,i,j,T; while(1) { sum=0; s
阅读全文
posted @ 2012-04-17 14:46
加拿大小哥哥
摘要:#include<stdio.h>int main(){ int a,b,sum,temp;int t,i,j,T; scanf("%d",&T); for(j=1;j<=T;j++) { sum=0; scanf("%d",&t); if(0==t) break; for(i=1;i<=t;i++) { scanf("%d",&temp); sum+=temp; } printf("%d\n",sum); } return 0;}//超时代码 //主要是用了上一题的
阅读全文
posted @ 2012-04-17 14:25
加拿大小哥哥
摘要:第一次没给sum赋初值,得出了一个绝对值超大的负数,而且sum=0要放在while内的其他语句之前,#include<stdio.h>int main(){ int sum,temp;int T; while(scanf("%d",&T),T) { sum=0; while(T--) { scanf("%d",&temp); sum+=temp; } printf("%d\n",sum); } return 0;}
阅读全文
posted @ 2012-04-17 14:15
加拿大小哥哥
摘要:#include<stdio.h>int main(){ int a,b; while(scanf("%d%d",&a,&b),a||b) { printf("%d\n",a+b); } return 0;} //错误代码,多了一个scanf语句 #include<stdio.h>int main(){ int a,b; while(scanf("%d%d",&a,&b),a||b) { scanf("%d%d",&a,&b); printf(
阅读全文
posted @ 2012-04-17 13:55
加拿大小哥哥
摘要:#include<stdio.h>int main(){ int a,b;int i,T; scanf("%d",&T); for(i=1;i<=T;i++) { scanf("%d%d",&a,&b); printf("%d\n",a+b); } //printf("\n");//必须去掉,否则PE(presentation error) return 0;}//pe代表结果正确,只是输出格式不对这样也对#include<stdio.h>int main(){
阅读全文
posted @ 2012-04-17 13:26
加拿大小哥哥