2016-02-25 Problem Solving►UVa UVa 12015 - Google is Feeling Lucky Contents 1. Problem2. Solution3. Code Problem題目網址 找出關聯值最高的URL,有相同時照輸入的順序輸出。 Solutionsort 後輸出關聯最高的URL即可,因為要保持相同關聯值時的相對順序,所以使用 std::stable_sort 。(不過一開始用 std::sort 也 AC 了…) CodeUVa 12015UVa 12015 - Google is Feeling Lucky12345678910111213141516171819202122232425262728293031323334#include<cstdio>#include<algorithm>struct Data{ char str[101]; int relevance;};int main(){ Data search[10]; int Case; scanf("%d", &Case); for (int i = 1; i <= Case; i++) { for (int j = 0; j < 10; j++) scanf("%s%d", search[j].str, &search[j].relevance); std::stable_sort(search, search + 10, [](const Data& a, const Data& b)->bool{ return a.relevance > b.relevance; }); printf("Case #%d:\n", i); int r = search[0].relevance; puts(search[0].str); for (int j = 1; search[j].relevance == r; j++) puts(search[j].str); } return 0;} Newer UVa 10306 - e-Coins Older UVa 357 - Let Me Count The Ways