單項選擇題
C程序中,已有語句int x;float y;char z;
scanf("%d%f%c",&x,&y,&z); ,要求使用變量x,y,z的值分別爲5,3.14,B,則正確的數據輸入方式是()。
以下對結構體類型point中成員x的不正確引用是( )
struct point
{ int x;
int y;
}a,*p;
p = &a;
編程題
第一題
#include <stdio.h> struct User { char *name[10]; double c1; double c2; double c3; }; int main() {
int garde[3]; int score[5]; int max_result=0; int result=0; struct User user[5]; //錄入數據 scanf("%d %d %d",&garde[0],&garde[1],&garde[2]); for(int i=0;i<5;i++) { scanf("%s %lf %lf %lf",user[i].name,&user[i].c1,&user[i].c2,&user[i].c3); } //計算 for(int i=0;i<5;i++) { score[i]=user[i].c1*garde[0]*0.01+user[i].c2*garde[1]*0.01+user[i].c3*garde[2]*0.01; if(score[i]>max_result) { max_result=score[i]; result=i; } } //輸出 printf("%s %d",user[result].name,max_result); system("pause"); return 0; }
超時啦!
第二題
A21表示11進制,後面21對應的十進制爲23
B10表示12進制,後面10對應的十進制爲13
Cb表示13進制,後面b對應的十進制爲11
第三題
#include <stdio.h> #include <math.h> #include <stdbool.h> /* 3 0 0 0 0 4 0 0 0 3 */ struct Node{ int x, y, z; }; double MAX = 0; int n; struct Node *t; //計算兩點之間的距離 double L3(int i, int j){ return sqrt((double)((t[i].x - t[j].x)*(t[i].x - t[j].x) + (t[i].y - t[j].y)*(t[i].y - t[j].y) + (t[i].z - t[j].z)*(t[i].z - t[j].z))); } //判斷是否是三角形 bool isSan(int i, int j, int k){ double a = L3(i, j); double b = L3(i, k); double c = L3(k, j); if (a < (b + c) && b < (a + c) && c < (a + b)) { return true; } return false; } //計算三角形面積 double CmputeArea(int i, int j, int k){ double a = L3(i, j); double b = L3(i, k); double c = L3(k, j); double p = (a + b + c) / 2; return sqrt(p * (p - a) * (p - b) * (p - c)); } //遍歷所有可能的三個點 void run(){ for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { if (isSan(i, j, k)) { double tArea = CmputeArea(i, j, k); if (tArea > MAX) { MAX = tArea; } } } } } } int main(){ //輸入 scanf("%d",&n); t=(struct Node*)malloc(sizeof(struct Node)*n); for (int i = 0; i < n; i++) { scanf("%d %d %d",&t[i].x,&t[i].y,&t[i].z); } //計算 run(); //輸出 printf("%.2lf\n", MAX); free(t); system("pause"); return 0; }
第四題