sicily 1177 Take Your Vitamins

感觉题目蛮无聊的....

 

// source code of submission 767064, Zhongshan University Online Judge System #include <iostream> #include <cstdio> #include <cstdlib> #include <string> using namespace std; struct node { float a,r,ratio; string unit,name; } v[1000]; int main() { int i = 0,y = 0,n = 0,yes[1000],no[1000]; //yes数组保存的是>=0.01的情况,而no数组是<0.01 float first,mid ; char temp[10]; string unit,name; cin>>first; while(first >= 0) { v[i].a = first; cin>>v[i].unit>>v[i].r; scanf("/n"); //这一行灰常重要 getline(cin,v[i].name); mid = v[i].a / v[i].r; if(mid >= 0.01) yes[y++] = i; else no[n++] = i; sprintf(temp,"%.2f",mid); //这里实现了保存两位小数 v[i].ratio = atof(temp)*100; i++; cin>>first; } if(y > 0) { for(i = 0;i < y;i++) { cout<<v[yes[i]].name<<" "; printf("%.1f ",v[yes[i]].a); cout<<v[yes[i]].unit<<" "; printf("%.0f",v[yes[i]].ratio); cout<<"%"<<endl; } } if(n > 0) { printf("Provides no significant amount of:/n"); for(i = 0;i < n;i++) cout<<v[no[i]].name<<endl; } return 0; }

你可能感兴趣的:(sicily 1177 Take Your Vitamins)