我想计算左边组中的行数是否是使该程序可以接受的配置。如果没有可接受的配置,则输出-1。程序在左a(X)中间b(x + 1)和右c(x + 2)处。有没有人比我的解决方案更好?
#include<stdio.h>
int main(void)
{
int chairs,a,b,c,result;
scanf("%d %d %d %d",&chairs,&a,&b,&c);
for(int i=1; i<=chairs; i++)
{
result= (a*(i)) + (b*(i+1)) + (c*(i+2));
if(chairs == result)
{
printf("%d",i);
break;
}
else if(i == chairs && chairs != result)
printf("-1");
}
}