期末考试有三种题型,选择题,每题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;
}