题解 | #Old Bill#

Old Bill

https://www.nowcoder.com/practice/17a30153e092493e8b4d13f321343927

#include <stdio.h>

// int N,price
// _678_ =   N*price
// price is interger,so use % to judge

// at first try to use string to campare XYZ,too complex and useless,cuz XYZ should represent known part of totalPrice

// for{1<five<9}{for{1<one<9{ price=_678_ %N  }}}
// cuz find the maximum, in for loop use --

int main() {
    int N,X,Y,Z;
    int price;
    int totalPrice;
    int i,j;

    scanf("%d\n%d %d %d",&N,&X,&Y,&Z);

    //totalPrice=N*price=10000*i+1000*X+100*Y+10*Z+j;

    for(i=9;i>0;i--){
        for(j=9;j>=0;j--){
            totalPrice=10000*i+1000*X+100*Y+10*Z+j;
            if(totalPrice%N==0){
                price=totalPrice/N;
                break;
            }
        }
        //trick:继续退出第二层循环 完整结束第二次for j==-1
        if(j!=-1){
            break;
        }
        else{
			j=0;
		}
    }

	//0 输出怎么解决
	if(i!=0){
		printf("%d %d %d",i,j,price);
	}
	else{
		printf("%d",i);
	}

    return 0;
}

0.退出循环的技巧

1.flag输出技巧

输入就很抽象好吧

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务