Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

选择c和gcc,结果不一样

Posted by znn_415 at 2013-12-13 18:13:32 on Problem 1004
下面这段程序,选择c编译AC,选择gcc编译Wrong Answer。估计问题应该是在库函数上,不知道用的gcc是什么版本的。

#include <stdio.h>
#include <string.h>
#include <stdlib.h> 

#define INPUT_MAX_NUM  12

int get_input_value(double *value)
{
#if 0
    double input;
    char s[100] = {0};
    char *endptr;
    
    scanf("%s", s);
    
    input = strtod(s, &endptr);
    if (endptr != s + strlen(s))
    {
        return -1;
    }
    
    *value = input;
#else
    scanf("%lf", value);
#endif
    
    return 0;
}

int main(void)
{
    int input_num = 0;
    double input = 0.0;
    double average = 0.0;

    while (input_num != INPUT_MAX_NUM)
    {
        if (get_input_value(&input) < 0)
        {
            continue;
        }
        
        input_num++;
            
        average += input;
    }
    
    printf("$%.2lf\n", average / input_num);
    
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator