Nine degrees OJ 1036 old Bill (analog)

Source: Internet
Author: User

Topic 1036:old Bill

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:2302

Resolution:1211

Title Description:

Among grandfather ' s papers a bill was found.
Turkeys $_679_
The first and the last digits of the number, the obviously represented the total price of those turkeys is replaced here By blanks (denoted _), for they is faded and is illegible. What is the faded digits and what is the price of the one turkey?
We want to write a program this solves a general version of the above problem.
N Turkeys $_xyz_
The total number of turkeys, N, is between 1 and, 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 are nonzero, that's the price of one turkeys are 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 both faded digits and the original price. In case that there was more than one candidate for the original price, the output should was the most expensive one. That was, the program was to report the faded digits and the maximum price per turkey for the turkeys.

Input:

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 is the three decimal digits X, Y, and Z., separated by a space, of the original price $_xyz_ .

Output:

For each case , the output of the faded digits and the maximum price per turkey for the turkeys.

Sample input:
726 7 952 3 7780 0 5
Sample output:
3 2 5119) 5 184750

#include <stdio.h>int n;int x;int y;int z;int a;int b;int ans;int check (int num) {    int sum=n*num;    if ((SUM/10)%10==z&& (sum/100)%10==y&& (sum/1000)%10==x)    {        a= (sum/10000)%10;        b= (sum%10);        Ans=num;        return 1;    }    return 0;} void output () {    printf ("%d%d%d\n", A,b,ans);} int main (int argc, char *argv[]) {    freopen ("1036.in", "R", stdin);    while (~SCANF ("%d", &n))    {        scanf ("%d%d", &x,&y,&z);        int m=99999/n;        for (int i=m;; -i)        {            if (check (i)) {                output ();                break;            }            if (i<=0) {                printf ("0\n");                Break    ;    }}} return 0;}


Nine degrees OJ 1036 old Bill (analog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.