|
Posted on 2011-08-27 01:12 Uriel 阅读(199) 评论(0) 编辑 收藏 引用 所属分类: 考研&保研复试上机题
这套很水。。 1. 球的半径和体积 脑残WA一次。。某个地方double写成int了。。
//2003年清华大学计算机研究生机试题 球的半径和体积
#include<math.h>
#include<stdio.h>
#define PI acos(-1)
double x, y, z, xx, yy, zz;
 double Dis(double x, double y, double z, double xx, double yy, double zz) {
return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz));
}
 int main() {
 while(~scanf("%lf %lf %lf %lf %lf %lf", &x, &y, &z, &xx, &yy, &zz)) {
double r = Dis(x, y, z, xx, yy, zz);
printf("%.3lf %.3lf\n", r, 4.0 * PI * r * r * r / 3.0);
}
return 0;
} 2. 查找学生信息 第N!次挂在多case上。。下次考虑是不是都写成多case的。。
//2003年清华大学计算机研究生机试题 查找学生信息

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

 struct M {
char id[100], name[200], sx[50], sco[50];
}p[1010];

int n, m;

 int main() {
int i;
char id[10];
 while(~scanf("%d", &n)) {
 for(i = 0; i < n; ++i) {
scanf("%s %s %s %s", p[i].id, p[i].name, p[i].sx, p[i].sco);
}
scanf("%d", &m);
 while(m--) {
scanf("%s", id);
 for(i = 0; i < n; ++i) {
 if(!strcmp(p[i].id, id)) {
printf("%s %s %s %s\n", p[i].id, p[i].name, p[i].sx, p[i].sco);
break;
}
}
if(i == n) puts("No Answer!");
}
}
return 0;
}3. 今年的第几天? 极其脑残地WA了一次。。
//2003年清华大学计算机研究生机试题 今年的第几天?

#include<stdio.h>

 int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

 int main() {
int i, m, y, d, ans;
 while(~scanf("%d %d %d", &y, &m, &d)) {
if(m == 1) printf("%d\n", d);
else if(m == 2) printf("%d\n", d + 31);
 else {
ans = 0;
for(i = 1; i < m; ++i) ans += mon[i];
if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) ans++;
ans += d;
printf("%d\n", ans);
}
}
return 0;
}
|