(暴力求解类)与7无关的数/百鸡争鸣/Old bill

1、KY50 与7无关的数

描述
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7, 则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。
输入描述:
案例可能有多组。对于每个测试案例输入为一行,正整数n,(n<100)
输出描述:
对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。

示例1

输入:
21
输出:
2336

#include <stdio.h>
int main()
{
    int n,i,sum;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1,sum=0;i<=n;i++)
            if(i%7!=0&&i%10!=7&&i/10!=7)
                sum+=i*i;
        printf("%d\n",sum);
    }
}

2、KY185 白鸡争鸣

描述
用小于等于n元去买100只鸡,大鸡5元/只,小鸡3元/只,还有1/3元每只的一种小鸡,分别记为x只,y只,z只。编程求解x,y,z所有可能解。
(本题没有测试数据,int main(){}就能通过真·本地过了就是过了)

输入描述:
测试数据有多组,输入n。
输出描述:
对于每组输入,请输出x,y,z所有可行解,按照x,y,z依次增大的顺序输出。
示例1

输入:
40

输出:
x=0,y=0,z=100
x=0,y=1,z=99
x=0,y=2,z=98
x=1,y=0,z=99

#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    for(int x=0;x<=100;x++){
        for(int y=0;y<=100;y++){
            for(int z=0;z<=100;z++){
                if((x*15+y*9+z<=3*n)&&(x+y+z==100)){
                    printf("x=%d,y=%d,z=%d\n",x,y,z);
                }
            }
        }
    }
}

3、KY95 Old Bill

描述
Among grandfather’s papers a bill was found. 72 turkeys $679 The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are illegible. What are the two faded digits and what was the price of one turkey? We want to write a program that solves a general version of the above problem. N turkeys $XYZ The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit is nonzero, that the price of one turkeys is an integer number of dollars, and that all the turkeys cost the same price. Given N, X, Y, and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should be the most expensive one. That is, the program is to report the two faded digits and the maximum price per turkey for the turkeys.
输入描述:
The first line of the input file contains an integer N (0<N<100), which represents the number of turkeys. In the following line, there are the three decimal digits X, Y, and Z., separated by a space, of the original price $XYZ.
输出描述:
For each case, output the two faded digits and the maximum price per turkey for the turkeys.对于每种情况,输出两个褪色的数字和火鸡每只火鸡的最高价格。

示例1

输入:
72
6 7 9
5
2 3 7
78
0 0 5

输出:
3 2 511
9 5 18475
0

#include<stdio.h>
int main(){
    int n,x,y,z,a,b,c,k=0,d,e;
    
    while(scanf("%d %d %d %d",&n,&x,&y,&z)!=EOF)
    {
        
        for(int a=1; a<10; a++)
        {
            for(int b=0; b<10; b++)
            {
                if((a*10000+x*1000+y*100+z*10+b)%n==0)
                {
                    int c;
                    c=(a*10000+x*1000+y*100+z*10+b)/n;
                    if(k<c)
                    {
                        k=c;
                        d=a;
                        e=b;
                    }
 
                }
            }
        }
        if(k==0)
        {
            printf("0\n");
        }
        else
        {
            printf("%d %d %d\n",d,e,k);
        }
    }
    
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值