Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

# 問題概要

\$3\$ つの整数 \$A,B,C\$が与えられる。

• \$A,B,C\$ のうち \$2\$ つを選んで、その両方を \$1\$ 増やす
• \$A,B,C\$ のうち \$1\$ つを選んで、その整数を \$2\$ 増やす

• \$0≤A,B,C≤50\$
• 入力はすべて整数である

# 考えたこと

これを\$(C-A)/2\$と\$(C-B)/2\$の剰余の結果ごとに場合分けして書けばよい。(剰余だと考えうる場合の数は4通りなので。)

# 解答

c.cs
``````using System;
using System.Linq;

class Program
{
static void Main(string[] args) {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(s);
Console.WriteLine(solve(s[0], s[1], s[2]));
}
static int solve(int a, int b, int c) { //a < b < c
int count = 0;
if ((c-b)%2 == 0 && (c-a)%2 == 0) {
count += (c-b)/2+(c-a)/2;
}
else if (((c-b)%2 == 0 && (c-a)%2 == 1) || ((c-b)%2 == 1 && (c-a)%2 == 0)) {
count += (c-b)/2 + (c-a)/2 + 2;
}
else {
count += (c-b)/2 + (c-a)/2 + 1;
}
return count;
}
}
``````
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?