#UVa:10424-Love Calculator

照題目要求之方法計算即可。

C++(0.016)

/*******************************************************/
/* UVa 10424 Love Calculator                           */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2015/01/08                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
using namespace std;

int valueCalculator(string name){
  int value = 0;
  for( int i = 0 ; i < name.length() ; ++i ){
    if( isalpha(name[i]) ){
      value += (int)tolower(name[i]) - (int)'a' + 1;
    }
  }
  while( value >= 10 ){
    value = value / 10 + value % 10;
  }

  return value;
}

int main(){
  string name1, name2;
  while( getline(cin, name1) ){
    getline(cin, name2);

    double value1 = valueCalculator(name1), value2 = valueCalculator(name2);
    printf("%.2lf %%\n", min(value1, value2) / max(value1, value2) * 100);
  }

  return 0;
}

發表迴響