C++的问题,帮我写个很简单的cpp,我是入门的级别所以不会很难
Student10.80.7500.2500.270.40.40.530.5800.6211.71.91.51.51.81.301.71.81.61.9Student20...
Student1 0.8 0.75 0 0.25 0 0.27 0.4 0.4 0.53 0.58 0 0.6 2 1 1.7 1.9 1.5 1.5 1.8 1.3 0 1.7 1.8 1.6 1.9Student2 0.9 0 0.7 0.66 0.4 0.69 0.55 0 0.8 0.63 0.53 0.1 2 1.8 1.9 2 1.2 0 1.7 1.5 0 0 1.3 1.8 1.7Student3 0.8 0.85 0.85 0.38 0.3 0 0.4 0 0 0.46 0.69 0.7 2 0 0 0 0 0.4 0 0 0 0 0 0 2Student4 0.9 0.85 0.77 0.63 0.9 0.73 0.6 0 0 0.48 0 0 1 1.8 1.9 0 1.8 0 1 1.3 1 0.6 1 1.8 0Student5 0.3 0.25 1.07 0.53 0 0 0.25 0.4 0.27 0.3 0.59 0.2 1.8 1.8 1.8 1.9 1.7 0 1.7 1.7 1.4 1.4 1.4 1.2 1.8Student6 0.8 0.7 0.55 0.59 0.7 0.47 0.5 0.45 0.6 0.7 0.59 0.5 2 1 1 1 1.6 1.9 1 1.9 2 2 0 1.4 1.7Student7 0.4 0.9 0.73 0.69 0.8 0.33 0.85 0.65 1.07 0.73 0.56 0.2 2 2 2 1.8 1.8 2 1.8 0 0 0 2 0.2 1.7Student8 0.8 0.9 0.9 0.63 0.6 0.6 0.7 0.4 0.27 0.2 0.38 0.4 2 2 1.8 1.9 1.8 0 0.9 0.1 0 1.6 0 0 0Student9 0.4 0 0.78 0 0.6 0.6 0.4 0 0 0 0.38 0.2 2 1.8 0.5 1 0 0 1.5 0 1.4 0 0 2 1Student10 1 0.95 1 0.69 0.1 0.8 0.9 0.65 0 0.65 0 1 2 2 1.8 1.9 2 2 2 2 2 1.4 1.8 0 1.7
在中午12点前需要完成。。。不会做求帮忙 展开
在中午12点前需要完成。。。不会做求帮忙 展开
2个回答
展开全部
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
void BubbleSort(float* pData, int count)
{
float temp;
for (int i = 1; i < count; i++)
{
for (int j = count - 1; j >= i; j--)
{
if (pData[j] < pData[j - 1])
{
temp = pData[j - 1];
pData[j - 1] = pData[j];
pData[j] = temp;
}
}
}
}
int main()
{
ifstream fin("EC7.txt", ios::in);
fstream fout("scoreSp15.txt",ios::out);
char line[1024]={0};
float ts[10][13]={0};
float hws[10][13]={0};
string sts[10][13]={"0"};
string shws[10][13]={"0"};
int j=0;
while(fin.getline(line, sizeof(line)))
{
stringstream word(line);
for(int i=0;i<13;i++)
{
word>>sts[j][i];
stringstream nums(sts[j][i]);
nums>>ts[j][i];
}
for(int i =0;i<13;i++)
{
word>>shws[j][i];
stringstream nums(shws[j][i]);
nums>>hws[j][i];
}
j++;
}
float tmptsarr[13];
float tmphwsarr[13];
float tmptssum=0.0;
float tmphwssum=0.0;
float labscore=0.0;
for(int m=0;m<10;m++)
{
for(int i=0;i<13;i++)
{
tmptsarr[i]=ts[m][i];
tmphwsarr[i]=hws[m][i];
}
BubbleSort(tmptsarr,13);
BubbleSort(tmphwsarr,13);
for(int i=12;i>2;i--)
{
tmptssum+=tmptsarr[i];
tmphwssum+=tmphwsarr[i];
}
labscore=tmptssum+tmphwssum;
if(labscore>30)
labscore=30;
ostringstream s1;
s1 << m+1;
string s2 = s1.str();
fout<<"Student"+s2<<" "<<labscore<<endl;
labscore=0.0;
tmptssum=0.0;
tmphwssum=0.0;
}
fin.close();
fout.close();
return 0;
}
我在ubuntu下,用qt写的,qmake构建通过
展开全部
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream ifs("EC7.txt");
double score[10][25]={0};
string name[10];
for(int i=0;i<10;i++)
{
ifs>>name[i];
for(int j=0;j<25;j++)
ifs>>score[i][j];
}
ifs.close();
for(int i=0;i<10;i++)
{
for(int j=0;j<12;j++)
for(int k =11;k>j;k--)
if(score[i][k]>score[i][k-1])
{
double temp = score[i][k];
score[i][k] = score[i][k-1];
score[i][k-1] = temp;
}
for(int j=0;j<13;j++)
for(int k=12;k>j;k--)
if(score[i][k+12]>score[i][k+11])
{
double temp = score[i][k+12];
score[i][k+12] = score[i][k+11];
score[i][k+11] = temp;
}
}
double lab[10]={0};
for(int i =0;i<10;i++)
{
for(int j=0;j<10;j++)
lab[i]+=score[i][j]+score[i][j+12];
lab[i]=(lab[i]>30)?30:lab[i];
}
ofstream ofs("scoreSp15.txt",ios::trunc|ios::out);
for(int i=0;i<10;i++)
ofs<<name[i]<<" "<<lab[i]<<"\r\n";
ofs.close();
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询