#include<stdio.h> #include<stdlib.h> #include<string.h> double y(double x){ double result; if(0<=x&&x<2.0) { result=-1*x+2.5; } else if(2<=x&&x<4){ result=2-1.5*(x-3.0)*(x-3.0); } else{ result=x/2-1.5; } return result; } int main(int argc, char *argv[]) { //freopen("1062.in", "r", stdin); double N; while(~scanf("%lf",&N)) { printf("%.3lf\n",y(N)); } return 0; } /************************************************************** Problem: 1062 User: kirchhoff Language: C Result: Accepted Time:10 ms Memory:912 kb ****************************************************************/
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/41925971