-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第二章:韩信点兵 #38
Comments
可以只列举7的倍数哦!然后再根据条件还原为测试人数,之后再判断是否符合其他条件 #include <stdio.h>
int main(){
int a,b,c,kase=0,hasans=0;
while(scanf("%d %d %d",&a,&b,&c)==3){
//这边我们边读入边计算
for (int i=14;i<=93;i=i+7){//列举7的倍数
int person=i+c;//猜测的总人数
if (person%3==a && person%5==b){//判断是否符合先前的条件
printf("Case %d: %d\n",++kase,person);//输出结果
hasans=1;//找到结果
break;//结束列举7倍数
}
}
if (!hasans){
printf("Case %d: No answer\n",++kase);//输出结果
}
hasans=0;
}
return 0;
} |
@kengwang |
感谢指出 |
#include<stdio.h> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#include<stdio.h>
int main()
{
int a[40],b[40],c[40],i;
int kase=0;
int x=0;
while(scanf("%d %d %d",&a[x],&b[x],&c[x])==3)
{
x++;
if(scanf("%d %d %d",&a[x],&b[x],&c[x])==3)
x++;
else
break;
}
}
The text was updated successfully, but these errors were encountered: