展开全部
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
int n;
int xh;
int yu,shu,ying;
float zf,pjf;
ifstream filein("cjb.in");
ofstream fileout("cjb.out");
char buffer[256];
char str1[200];
if(!filein)
{cout << "读入cjb.in文件创建失败!\n";
exit(1);
}
if(!fileout){
cout << "写入cjb.out文件创建失败!\n";
exit(1);
}
filein.getline(buffer,256);
sscanf(buffer,"%d",&n);
//cout<<n<<endl;
for(int i=0;i<n;i++){
filein.getline(buffer,256);
sscanf(buffer,"%d %d %d %d %s",&xh,&yu,&shu,&ying,str1);
cout<<xh<<" "<<yu<<" "<<shu<<" "<<ying<<" "<<(yu+shu+ying)<<" "<<fixed<<setprecision(1)<< (yu+shu+ying)/3.0<<endl;
fileout<<xh<<" "<<yu<<" "<<shu<<" "<<ying<<" "<<(yu+shu+ying)<<" "<<fixed<<setprecision(1)<< (yu+shu+ying)/3.0<<endl;
}
filein.close();
fileout.close();
system("PAUSE");
return 0;
}
执行结果如下:
注意先准备好需要读入的文件cjb.in
追问
嗯,谢谢
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<bits/stdc++.h>
struct Stu{
int int id,chi,math,eng,sum;
float arr;
Stu(){id=chi=math=eng=sum=0}
void init(int iid,int x,int y,int z){
id=iid;chi=x;math=y;eng=z;sum=x+y+z;arr=1.0*((float)sum)/(float)3;
}
bool operator < (const Stu a) const{
return arr>a.arr;
}
void print(){
printf("%d %d %d %d %d %.2f\n",id,chi,math,eng,sum,arr);
}
};
vector<Stu> v;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int iid,x,y,z;
cin>>iid>>x>>y>>z;
Stu tp;
tp.init(iid,x,y,z);
v.push_back(tp);
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
v[i].print();
}
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询