-
Notifications
You must be signed in to change notification settings - Fork 0
/
Names scores.cpp
executable file
·86 lines (84 loc) · 1.58 KB
/
Names scores.cpp
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
#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<functional>
using namespace std;
bool comp(const string &lhs,const string &rhs);
string get(istringstream & in);
int calc(const string&,const int );
int main()
{
unsigned long res=0;
ifstream inn("name");
ofstream out("ha");
string s;
inn>>s;
istringstream in(s);
set<string,function<bool(const string&,const string&)>> store(&comp);
while(in)
{
store.insert(get(in));
}
int line=1;
for(auto &i:store)
{
res+=calc(i,line);
// out<<i<<endl;
++line;
}
cout<<res;
}
string get(istringstream & in)
{
while(true)
{
while(in.get()=='\"')
{
string result;
char buf;
while(true)
{
buf=in.get();
if(buf=='\"')
{
in.get();
return result;
}
result+=buf;
}
}
}
}
bool comp(const string &lhs,const string &rhs)
{
int len=min(lhs.size(),rhs.size());
int ite=0;
while(ite!=len)
{
if(lhs[ite]==rhs[ite])
{
++ite;
continue;
}
else if(lhs[ite]<rhs[ite])
return true;
else
return false;
}
if(lhs.size()>rhs.size())
{
return false;
}
else
return true;
}
int calc(const string& s,const int line){
int sum=0;
for(auto &i:s){
sum+=i-64;
}
return sum*line;
}