def highest_score(words: str) -> str:
pass
assert highest_score("hogwarts is the best") == "hogwarts"
assert highest_score("harry potter and the order of the phoenix") == "potter"
assert highest_score("aaa b") == "aaa"
assert highest_score("aa b") == "aa"
assert highest_score("b aa") == "b"
def highest_score(words: str) -> str:
maximum = 0
score = lambda x: sum(ord(i)-ord('a')+1 for i in x)
for word in words.split():
word_score = score(word)
if word_score > maximum :
maximum = word_score
max_word = word
return max_word
def highest_score(words: str) -> str:
score = lambda x: sum(ord(i)-ord("a")+1 for i in x)
return max(words.split(), key = score)
public String highestScore(String s) {
String[] s1 = s.split(" ");
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
for (int i = 0; i < s1.length; i++) {
int result = 0;
char[] chars = s1[i].toCharArray();
for (int j = 0; j < chars.length; j++) {
result = result + (int) chars[j] - 96;
}
stringIntegerHashMap.put(s1[i], result);
}
Set<Map.Entry<String, Integer>> entries = stringIntegerHashMap.entrySet();
Iterator<Map.Entry<String, Integer>> iterator = entries.iterator();
int maxSum = 0;
String res = "";
while (iterator.hasNext()) {
Map.Entry<String, Integer> next = iterator.next();
Integer value = next.getValue();
String key = next.getKey();
if (value > maxSum) {
maxSum = value;
res = key;
}
}
return res;
}
@Test
public void highestScoreTest() {
assert highestScore("hogwarts is the best").equals("hogwarts");
assert highestScore("harry potter and the order of the phoenix").equals("potter");
assert highestScore("aaa b").equals("aaa");
}
def highest_score(words: str) -> str:
word_list=words.split(' ')
max_score = 0
result = word_list[0]
for word_item in word_list:
temp=0
for i in word_item:
temp += ord(i)
if temp>max_score:
max_score=temp
result=word_item
return result
import string
def highest_score(words: str) -> str:
chars = '0'+string.ascii_lowercase
words = words.split()
all_counts = []
for word in words:
count = 0
for c in word:
count += chars.index(c)
all_counts.append(count)
return words[all_counts.index(max(all_counts))]
assert highest_score("hogwarts is the best") == "hogwarts"
assert highest_score("harry potter and the order of the phoenix") == "potter"
assert highest_score("aaa b") == "aaa"
assert highest_score("aa b") == "aa"
assert highest_score("b aa") == "b"
def highest_score(words: str) -> str:
return max(words.split(), key=lambda word:sum(ord(c)-96 for c in word))
assert highest_score("hogwarts is the best") == "hogwarts"
assert highest_score("harry potter and the order of the phoenix") == "potter"
assert highest_score("aaa b") == "aaa"
assert highest_score("aa b") == "aa"
assert highest_score("b aa") == "b"