-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighestScoringWord.cpp
More file actions
71 lines (64 loc) · 1.6 KB
/
HighestScoringWord.cpp
File metadata and controls
71 lines (64 loc) · 1.6 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
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <sstream>
#include <climits>
using namespace std;
string highestScoringWord(const string& str) {
string result;
string temp;
int resulttemps = 0;
int flage = 0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] != ' ')
{
resulttemps += str[i] - 'a' + 1;
temp += str[i];
}
else
{
if (resulttemps > flage)
{
flage = resulttemps;
resulttemps = 0;
result = temp;
}
temp.clear();
resulttemps = 0;
}
}
if (resulttemps > flage)
{
result = temp;
temp.clear();
}
return result;
}
int main()
{
cout << highestScoringWord("aa b");
return 0;
}
/*Description:
Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the alphabet : a = 1, b = 2, c = 3 etc.
For example, the score of abad is 8 (1 + 2 + 1 + 4).
You need to return the highest scoring word as a string.
If two words score the same, return the word that appears earliest in the original string.
All letters will be lowercase and all inputs will be valid.
Fundamentals
Strings
Arrays*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU