Getting algorithm - the wrong title set

A, C language up, rounded down problem

math library - ceil function is taken over the entire, floor function is to remove the entire

ceil , to return the smallest integer greater than or equal to the specified expression , usage is Double ceil . It returns an integer not smaller than the lower value, value if there is a fractional part of the feed; ceil type of return is still float , because the value range of float is usually bigger than the integer

 

 

Exercise:

Select whether expedited postage based on the weight of the king and garlic mail. Calculation rules: weight of 1000 or less grams (including 1000 g), basic fee . 8 million.

Exceeds 1000 g portions, each 500 gram yield overweight . 4 million, less than 500 grams of partially press 500 calculates g;

If you choose expedited Jun garlic, overcharged 5 million.

Input Format

Input line, contains a positive integer and a character, separated by a space, respectively, represents the weight (in grams, no greater than 2⋅1052 \ ^ 10. 5 CDOT 2 . 1 0 . 5) and whether expedited.

If the character is 'y', the selection expedited; if the character is 'n'explained not expedited.

#include <stdio.h>
#include <math.h>
int main(){
    int n,x;
    char ji;
    scanf("%d %c",&n,&ji);
    if(ji == 'y'){
        if(n < 1000){
            printf("13");
        }else{
            x = (int) ceil((double) (n-1000)/500);
            printf("%d", 13+ x * 4);
        }
    }else{
        if(n < 1000){
            printf("8");
        }else{
           x = (int) ceil((double) (n-1000)/500);
            printf("%d", 8+ x * 4);
        }
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/expedition/p/11286782.html