Hang brushes title

This blog link: https://www.cnblogs.com/ping2yingshi/p/12395220.html

1. Operators vegetables (22min)

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=2090

Problem Description
Mother out to buy food every day, but came back, pocket money do not bother to count, in the end how much money is really a mess. Well now, as a good son (daughter) of the program you can give her count, huh, huh.
 
Input
Contains some input data sets, each data comprising rapeseed (string), the number (unit of measurement regardless of, all the number of double type) and monovalent (double type number that represents the number of cells RMB), and therefore, each data vegetables the number is multiplied by the unit price ah. Vegetable seeds, between quantity and unit price are separated by spaces.
 
Output
When payment of vegetables, because the angle is minimum payment unit, when it is always rounded off payment method to separately removed. Finally, the output accuracy of a total amount of vegetable angle.
 
Sample Input
Vegetables 12
Loeb 2 1.5
Chicken 2 4.2
 
Sample Output
13.4
answer:
         How much time processing of data mainly on how this question while reading strings and numbers, and do not know to sample there.
        Ideas:
        1. To define a character string type.
        2. scanf () can continue to take anti-enter until it encounters end of file.
       Note: When using the VS editor, you need to fill in the size of the input end of the string, otherwise compilation errors.
       code show as below:
int main()
{
    char vegname[100];
    double count;
    double prise;
    double sum=0;
    while (scanf_s("%s%lf%lf", vegname,100,&count,&prise)!=EOF )
    { 
        sum += count * prise; 
    }
    printf("%0.1lf\n", sum);
    return 0;
}

2.Fibbonacci Number(50min)

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=2070

Problem Description
Your objective for this question is to develop a program which will generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50.
 
Input
Each test case consists of one integer n in a single line where 0≤n≤50. The input is terminated by -1.
 
Output
Print out the answer in a single line for each test case.
 
Sample Input
3
4
5
-1
 
Sample Output
2
3
Note:
you can use 64bit integer: __int64
answer:
        Method: or Recursive cycles.
        NOTE: This problem may write very fast, but still not ac due to see the subject of a number range, the results of this question may be very large, I follow the topic to define a variable of type _int64, pay attention to the output format.
       Time consuming reason: I started using recursion to do this problem, but the data type is the return value can not be directly returned __int64 __int64, where to find a lot of information page not found how to return function value __int64 type.
code show as below:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int n;
    _int64 result[10000];
    while (~scanf_s("%d",&n))
    { 
        if (n == -1)
            break;
        result[0] = 0;
        result[1] = 1;
        int i = 0;
        for (i = 2; i <= n; i++)
            result[i] = result[i - 1] + result[i - 2];
        printf("%I64d\n", result[n]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/ping2yingshi/p/12395220.html