-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.cpp
More file actions
88 lines (84 loc) · 1.44 KB
/
Copy pathscore.cpp
File metadata and controls
88 lines (84 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
struct st
{
string name;
string sex;
string score;
}s[32];
int p2(const st &x)
{
int n;
char num[10] ;
strcpy(num,x.name.c_str());
for(int j=0;j<10;j++)
{
if((num[j]>='0')&&(num[j]<='9'))
n=num[j];
}
return n;
}
bool p1(const st &x, const st &y)
{
double a=stof(x.score);
double b=stof(y.score);
int c=p2(x);
int d=p2(y);
if(a==b)
return d>c;
else
return a>b;
}//排序
int main()
{
ifstream fin("score.csv");
string line;
getline(fin,line);//先读首行不进行操作
int i=0;
double t;
double m=0,g=0,m1=0,g1=0;
while(getline(fin,line))
{
istringstream sin(line);
vector<string> fields;
string field;
while (getline(sin,field,','))
{
fields.push_back(field);
}
s[i].name = fields[0];
s[i].sex = fields[1];
s[i].score = fields[2];
if(s[i].sex==" Male")
{
m++;
t=stof(s[i].score);
m1+=t;
}
else
{
g++;
t=stof(s[i].score);
g1+=t;
}
i++;
}
double m2=m1/m,g2=g1/g;
cout<<"男生平均分为:"<<m2<<endl;;
cout<<"女生平均分为:"<<g2<<endl;
for(int k=0;k<32;k++)
{
sort(s,s+32,p1);
}
for(int k=0;k<32;k++)
{
cout<<s[k].name<<","<<s[k].sex<<","<<s[k].score<<endl;
}
return 0;
}