1. puts和printf:
#include "stdio.h" int main(void) { puts(10 > 8 ? "OK" : "Sorry"); } | 运行结果: 请按任意键继续. . .[微软用户1] |
#include "stdio.h" int main(void) { printf(10 > 8 ? "OK" : "Sorry"); } | 运行结果: OK请按任意键继续. . . |
2. #include <math.h>
#include <stdio.h>
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
printf("%.0f[微软用户2] /n", 3 * pow(2, n - 1) - 2);
}
3.
#include"stdio.h" #include"stdlib.h" typedef struct node { int data; struct node *next; }linklist; int main() { linklist *head,*p,*tail; int x; head=tail=NULL; scanf("%d",&x); while (x!=0) { p=(linklist *)malloc(sizeof(linklist)); p->data=x; p->next=NULL; if (head==NULL) head=tail=p; else { tail->next=p; tail=p; } scanf("%d",&x); // return(head); } while(x!=0) { printf("%d",head->data); head=head->next; } } | 没有输出结果,为什么呢??? |
4.HDOJ-NO.2000错在哪里?
#include"stdio.h" #include"algorithm" int main() { char a,b,c,t; while(scanf("%c%c%c",&a,&b,&c)!=EOF) { if(a>b) swap(a,b); if(b>c) swap(b,c); if(a>b) swap(a,b); printf("%c%c%c%c%c/n",a,' ',b,' ',c); } } | 运行结果: qwe e q w asd
a s zxc
d z
c x | 预期结果: qwe e q w asd a d s zxc c x z |
5. HDOJ-NO.2001
2001#include"stdio.h" #include"math.h" int main() { double x1,y1,x2,y2; while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF) printf("%.2f/n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))); }
|
6. HDOJ-NO.2002
#include"stdio.h" #define PI 3.1415926 int main() { double r; while(scanf("%lf",&r)!=EOF) printf("%.3f/n",4.0/3.0*PI*r*r*r); } |
7. HDOJ-NO.2003
#include"stdio.h" #include"math.h" int main() { double x; while(scanf("%lf",&x)!=EOF) printf("%.2f/n",fabs(x)); } |
8. HDOJ-NO.2004
#include"stdio.h" main() { double score; while (scanf("%lf",&score)!=EOF) { if (score>100||score<0) printf("Score is error!/n"); else { switch ((int)(score/10)) { case 10: case 9: printf("A/n"); break; case 8: printf("B/n"); break; case 7: printf("C/n"); break; case 6: printf("D/n"); break; default: printf("E/n"); break; } } } } |
9. HDOJ-NO.2005
#include <stdio.h> /* 计算某个日期对应该年的第几天 */ int day_of_year(int year, int month, int day) { int k, leap; int tab[2][13] = /* 数组初始化,将每月的天数赋给数组 */ { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; /* 判断year是否为闰年,当year是闰年时,leap=1;当year是非闰年时,leap=0 */ leap = (year % 4 == 0 && year%100!=0 || year%400==0); /* 计算天数 */ for (k = 1; k < month; k++) day = day + tab[leap][k]; return day; } int main(void) { int year, month, day; while (scanf("%d/%d/%d", &year,&month, &day)!=EOF) printf("%d/n", day_of_year(year, month, day)); } |
10. HDOJ-NO.2006
#include <stdio.h> int main() { int x,n,total; while(scanf("%d",&n)!=EOF) { total=1; while(n--) { scanf("%d",&x); if(x%2==1) total*=x; } printf("%d/n",total); } } |
11. HDOJ-NO.2007
#include <stdio.h> int main() { int i,n,m,total1,total2; while (scanf("%d%d",&m,&n)!=EOF) { total1=0; total2=0; for (i=m;i<=n;i++) if (i%2==0) total1+=(i*i); else total2+=(i*i*i); printf("%d %d/n",total1,total2); } } |
12. HDOJ-NO.2008
#include"stdio.h" int main() { double x; int n,total1,total2,total3; while (scanf("%d",&n)!=EOF&&n) { total1=0; total2=0; total3=0; while (n--) { if (x<0.0) total1++; else if (x>0.0) total3++; else total2++; } printf("%d %d %d/n",total1,total2,total3); } } |
13. HDOJ-NO.2009
#include"stdio.h" #include"math.h" int main() { int m,i; double sum,n; while(scanf("%lf%d",&n,&m)!=EOF) { sum=0; for (i=1;i<=m;i++) { sum+=n; n=sqrt(n); } printf("%.2f/n",sum); } } |