Logo
(追記) (追記ここまで)

10193번 - Word Swap 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB32212410739.925%

문제

Agnes has heard that the carnival is going to have a new game next year. The carnival guy chooses a word and writes it down on a piece of paper, and only tells you the length of the word (lets call it Word 1). You have to guess a word of the same length (lets call it Word 2), and you earn or lose coins depending on how different are the two words (i.e., based on how much effort is required to swap the two words). Agnes, having just turned 6, has barely started reading and can’t do math yet, so she wants your help to play this game.

The carnival provided the following rules for earning or paying coins.

  • Only letters a-z will be used in the game.
  • The difference between words is decided on a position-by-position basis.
  • For each position: (1) if the characters in that position in the two words are the same, no coins are paid or earned; (2) if the character in Word 1 at that position appears alphabetically before the character in Word 2, then you have to pay 1 coin for each character between the two characters and 1 additional coin; (3) if the character in Word 1 at that position appears alphabetically after the character in Word 2, then you earn 1 coin for each character between the two characters and 1 additional coin.

For example: if the carnival guy wrote down agnes and you guessed heard, then the following table shows the calculation.

Position 1 Position 2 Position 3 Position 4 Position 5 Total
Carnival Word a g n e s
Your Word h e a r d
Coins paid 7 earned 2 earned 13 paid 13 earned 15 earned 10
  • You might think this is not particularly interesting game, since one can always guess words like “aal”, “abut”, etc. (depending on length), and easily earn coins. However, there is a twist: if it turns out you would earn too many coins, you don’t earn anything (its a carnival game after all). We will ignore this twist.

You have to write a program that tells Agnes how many coins she will earn or have to pay for a pair of words. The program will read in a series of pairs of words and report the amount paid or earned. The provided skeleton handles the input of the words and the output messages. You need to implement the method costToSwap which returns an integer.

입력

The first line in the test data file contains the number of test cases. After that each line will contain two words separated by a space.

출력

For each test case, the program will display the number of coins paid or earned.

제한

출력 형식

정확한 출력 형식은 제출에서 언어를 Java로 설정하면 확인할 수 있다.

예제 입력 1

4
agnes heard
unicorn minions
victor vector
sweat waste

예제 출력 1

Swapping letters to make agnes look like heard earned 10 coins.
Swapping letters to make unicorn look like minions earned 1 coins.
Swapping letters to make victor look like vector earned 4 coins.
Swapping letters to make sweat look like waste was FREE.

힌트

출처

School > University of Maryland High School Programming Contest > HSPC 2014 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /