#UVa:12015-Google is Feeling Lucky

每筆測資有十個網址,將十個網址中具有最大值的網址們印出即可。

C++(0.000)

/*******************************************************/
/* UVa 12015 Google is Feeling Lucky                   */
/* Author: LanyiKnight [at] knightzone.studio             */
/* Version: 2016/03/14                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <climits>
#include <string>
#include <vector>
using namespace std;

int main(){
  const int URL_NUMBER = 10;

  int T;
  while( scanf("%d", &T) != EOF ){
    for( int i = 1 ; i <= T ; ++i ){
      vector<string> urls;
      int maxRelevance = INT_MIN;

      string url;
      int relevance;
      for( int j = 0 ; j < URL_NUMBER ; ++j ){
        cin >> url;
        scanf("%d", &relevance);

        if( relevance > maxRelevance ){
          maxRelevance = relevance;
          urls.clear();
          urls.push_back(url);
        }
        else if( relevance == maxRelevance ){
          urls.push_back(url);
        }
      }

      printf("Case #%d:\n", i);
      for( int j = 0 ; j < urls.size() ; ++j ){
        printf("%s\n", urls[j].c_str());
      }
    }
  }

  return 0;
}
廣告

Comment

There is no comment on this post. Be the first one.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: