C++ 代码
#include<bits/stdc++.h>
using namespace std;
float y(float n){
if(n==0 || n==1)return -1*n+2.5;
else if(n==2 || n==3)return 2-1.5*pow(n-3,2);
else return n/2-1.5;
}
int main(){
float T,x;
cin>>T;
while(T--){
cin>>x;
printf("y=%.1f\n",y(x));
}
return 0;
}