Răspuns :
#include <iostream>
#include<fstream>
using namespace std;
ifstream fin("ech.in");
ofstream fout("ech.out");
long long i,j,n,m,sump,sumip;
int main()
{
fin >> n;
while(true)
{
n++;
m=n;
j=0;
sump=0;
sumip=0;
while(m)
{
j++;
if(j%2 == 0)
sump=sump+(m%10);
if(j%2 != 0)
sumip=sumip+(m%10);
m/=10;
}
if(sump == sumip)
{
fout << n;
break;
}
}
return 0;
}
nu stiu daca o sa iti ia toate punctele
#import <iostream>
#include <fstream>
#include <cstring>
using namespace std;
void increment(char number[])
{
/** Increments a number given as string.
*
* @param number: the number to be incremented
*/
int current_position = 1;
while (number[strlen(number) - current_position] == '9')
{
number[strlen(number) - current_position] = '0';
current_position++;
}
number[strlen(number) - current_position]++;
}
/** The function checks if a given number is "balanced". A number is "balanced" if the sum of the digits with odd indexes
* is equal to the sum of the digits with even indexes.
*
* @param number: string containing the number to be checked.
* @return: true if the number is balanced, false otherwise.
*/
bool is_balanced(char number[])
{
int sum_odd = 0, sum_even = 0;
for (int index = 0; index < strlen(number); index += 2)
{
sum_even += number[index];
}
for (int index = 1; index < strlen(number); index += 2)
{
sum_odd += number[index];
}
return sum_even == sum_odd;
}
int main()
{
ifstream fin("ech.in");
ofstream fout("ech.out");
char number[23];
fin.getline(number, sizeof(number));
increment(number);
while(!is_balanced(number))
increment(number);
fout << number;
return 0;
}
Vă mulțumim pentru vizita pe site-ul nostru dedicat Informatică. Sperăm că informațiile prezentate v-au fost utile. Dacă aveți întrebări sau aveți nevoie de suport suplimentar, nu ezitați să ne contactați. Ne bucurăm să vă revedem și vă invităm să ne adăugați în lista de favorite!