资讯详情

N-FX1-3

期末考试有三种题型,选择题,每道题2.3分,填空题,每题3分.4分,编程题,每题12分。

张小元总共做了n个问题,最后的分数是m,张小元做了选择题,填空题和编程题各有几个。如果没有解决方案,输出Error! 输入:做出的总题数n,最终得分m 输出:依次输出编程题、填空题、选择题的数量。如果多组结果符合条件,则按编程题数量、填空题数量和选择题数量依次降序输出。

# include<stdio.h> # include<math.h> /*期末考试有三种题型,选择题,每道题2.3分,填空题,每题3分.4分,编程题,每题12分。 张小元总共做了n个问题,最后的分数是m,问张小元做选择题, 填空题和编程题各有几道。如无解,输出Error! 输入:总题数n,最终得分m 若有多组结果符合条件,则输出:依次输出编程题、填空题和选择题的数量, 根据编程题的数量,填空题的数量和选择题的数量依次降序输出。 */  typedef struct tes {  int bian;  int tian;  int xuan; }TES; TES test[10], temp; int main() {    int n = 0;  int m = 0;  int  num = 0;  scanf("%d %d",&n, &m);  for(int i = 0;i <= n; i   )  {   for(int j = 0;j <= n- i;j   )   {    if(fabs(i * 12   j * 3.4   2.3*(n-j-i)-m) < 1e-6)    {     test[num].bian = i;     test[num].tian = j;     test[num].xuan = n - i - j;     num   ;    }   }  }  if(num == 0)  {   printf("Error!\n");  }  else  {   for(int i = 0;i < num -1 ;i  )   {     for(int q = 0;q < num-i-1;q   )    {     if(test[q].bian > test[q 1].bian)     {      temp = test[q];      test[q]=test[q 1];      test[q 1]=temp;     }    }   }   for(int i = 0;i < num -1 ;i  )   {     for(int q = 0;q < num-i-1;q   )    {     if(test[q].tian > test[q 1].tian && test[q].bian==test[q 1].bian)     {      temp = test[q];      test[q]=test[q 1];      test[q 1]=temp;     }    }   }       for(int i = num-1;i >= 0;i --)   {    printf("%d %d %d\n", test[i].bian, test[i].tian, test[i].xuan);   }  }  return 0; }

标签: fx1风向传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司