Произведем вывод формулы расчета количества лопастей:




Так как все операнды целые числа, мы имеем целочисленное деление и целое число в результате. Это сравнимо с округлением вниз, поэтому С по стоимости мы не перепрыгнем.
Код:
#include <iostream>
long long calculate_spin_number(
long long A,
long long B,
long long C
) {
return std::max((C - A) / B, 0ll);
}
int main () {
long long A, B, C;
std::cin >> A >> B >> C;
std::cout << calculate_spin_number(A, B, C) << std::endl;
return 0;
}
Функция calculate_spin_number() рассчитывает количество лопастей по параметрам A, B, C.
(!!) Внимание! Мы не можем использовать int или unsigned int для хранения чисел такого размера как 20000000000. Нужно использовать long или long long.
===========================================================
Если ответ удовлетворил, не забудь отметить его как "Лучший".
Код:
using System;
namespace WordsCounter
{
class Bishop
{
private int x, y;
public Bishop(int x, int y)
{
this.x = x;
this.y = y;
}
public bool CanIAttackIt(int x, int y)
{
return Math.Abs(x - y) == Math.Abs(this.x - this.y);
}
}
class Program
{
static void Main(string[] args)
{
var x0 = int.Parse(Console.ReadLine()!);
var y0 = int.Parse(Console.ReadLine()!);
var x = int.Parse(Console.ReadLine()!);
var y = int.Parse(Console.ReadLine()!);
Console.WriteLine((new Bishop(x0, y0)).CanIAttackIt(x, y));
}
}
}


Код:
using System;
namespace WordsCounter
{
class Bishop
{
private int x, y;
public Bishop(int x, int y)
{
this.x = x;
this.y = y;
}
public bool CanIAttackIt(int x, int y)
{
return Math.Abs(x - y) == Math.Abs(this.x - this.y);
}
}
class Program
{
static void Main(string[] args)
{
var x0 = int.Parse(Console.ReadLine()!);
var y0 = int.Parse(Console.ReadLine()!);
var x = int.Parse(Console.ReadLine()!);
var y = int.Parse(Console.ReadLine()!);
Console.WriteLine((new Bishop(x0, y0)).CanIAttackIt(x, y));
}
}
}


Так и не получил ответ, надо считать A + B * N или (A + B) * N, поэтому использовал второй вариант. Если что, можно легко поменять.
На C++:
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int main() {
setlocale(0, "RU");
try {
string InputError = "Ошибка ввода";
cout << "Введите стоимость основания спиннера: ";
int a;
cin >> a;
if (cin.fail()) {
throw(InputError);
}
cout << "Введите стоимость одной лопасти: ";
int b;
cin >> b;
if (cin.fail()) {
throw(InputError);
}
cout << "Введите максимальную цену всего спиннера: ";
int c;
cin >> c;
if (cin.fail()) {
throw(InputError);
}
int max = 20000000000;
if (a <= c && a != max && b != max && c != max) {
int n = 1;
while (true) {
if ((a + b) * n <= c) {
n++;
}
else {
n--;
break;
}
}
system("cls");
cout << n;
}
else {
string InvalidValues = "Недопустимые значения";
throw(InvalidValues);
}
}
catch (string a) {
cout << "\n" << a << "...";
_getch();
}
return 0;
}