CF845B.Luba And The Ticket

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.

The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

卢巴有一张由 6 位数字组成的车票。在一次操作中,她可以选择任意位置上的数字,并将其替换为任意数字。她想知道,为了使这张车票变成“幸运车票”,她至少需要替换多少位数字。

当车票的前三位数字之和等于后三位数字之和时,该车票即被视为“幸运车票”。

输入格式

You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

你将得到一个由 6 个字符组成的字符串(所有字符均为数字 0 到 9)——该字符串表示卢巴的车票。车票可能以数字 0 开头。

输出格式

Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

输出一个数字——Luba 需要替换的最少数字个数,以使这张票变为幸运票。

输入输出样例

  • 输入#1

    000000

    输出#1

    0
  • 输入#2

    123456

    输出#2

    2
  • 输入#3

    111000

    输出#3

    1

说明/提示

In the first example the ticket is already lucky, so the answer is 0.

In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.

In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.

在第一个例子中,这张票已经是幸运的,因此答案为 0。

在第二个例子中,Luba 可以将 4 和 5 替换为 0,从而使这张票变为幸运的。显然,至少需要两次替换。

在第三个例子中,Luba 可以将任意一个 0 替换为 3。显然,至少需要一次替换。

输入解题思路,AI测评打分。不知道怎么写?

首页