zoukankan      html  css  js  c++  java
  • 题目1062:分段函数23333333333333

    超简单的模拟,本来想耍帅,用#include<iomanip>  cout<<setiosflags(ios::fixed)<<setprecision(3)<<res;来AC,结果WA;

    WA的代码:正大眼睛好好看看,没错是WA

    #include<iostream> 
    #include<iomanip>
    using namespace std;
    int main()
    {
    	double x;
    	double res;
    	while(cin>>x)
    	{
    	    if (x>=0 && x<2)
    		  res=0-x+2.5;
    	    if (x>=2 && x<4)
    		     res=2-1.5*(x-3)*(x-3);
    		if(x>=6 && x<4)
    			  res=x/2-1.5;
             cout<<setiosflags(ios::fixed)<<setprecision(3)<<res<<endl;
    	}
    	return 0;
    }
    

    AC的代码:没有看错,只是换了一个简单的输出方式

    #include<stdio.h>
    int main()
    {
    	double x;
    	while(scanf("%lf",&x)!=EOF)
    	{
    		if (x>=0 && x<2)
    		  x=-x+2.5;
    		  else if(x>=2 && x<4)
    		  x=2-1.5*(x-3)*(x-3);
    		  else if (x>=4 && x<6)
    		  x=x/2-1.5;
    	 printf("%.3lf
    ",x); 
    	}	
    	return 0;
    }
    

      

  • 相关阅读:
    ajax01
    django04
    数据库
    WeakHashMap类
    IdentityHashMap
    Hashtable类
    LinkedHashMap类
    HashMap和TreeMap类
    PriorityQueue
    Synchronized
  • 原文地址:https://www.cnblogs.com/jianrenguo/p/6475812.html
Copyright © 2011-2022 走看看