Zabwne dodawnie Piotrusia

0

Witam, robię zadanie ze spoja, w którym po podaniu liczby mam dodawać ją i jej odwrotność do momentu, aż nie znajdę palindromu. Coś już nagryzmoliłem, ale nie za bardzo ogarniam jak to zapętlić. POMOCY!!
Link: http://pl.spoj.com/problems/BFN1/

# include <iostream>
# include <cstdio>
# include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int main ()
{
    string liczba;
    bool a=true;
    cin>>liczba;
    int d=liczba.length();
    int i=0;
    do
    {
        if(liczba[i]!=liczba[d-1-i]) a=false;
        i++;
    }
    while(a&&i<d/2);
    if(a) cout<<liczba<<" 0";
    else
    {
        string h;
        for (int i=d-1; i>=0; i--)
        {
            h=h+liczba[i];
        }
        int e = atoi(h.c_str());
        cout<<e<<endl;
        int f =atoi(liczba.c_str());
    int suma = f+e;
        cout <<suma;
  }
    return 0;
} 
1
#include <iostream>
#include <math.h>
using namespace std;

bool checkIsPalindrom(int num){
	int n = num;;
	int rev = 0;
	int dig;
	while (num > 0)
	{
		dig = num % 10;
		rev = rev * 10 + dig;
		num = num / 10;
	}
	return n == rev;

}

int reverse(int num){
	int LiczbaCyfr = floor(log10(num) + 1);
	int k = 0;
	for (int i = 0; i<LiczbaCyfr; i++)
	{
		k += pow(10.0, LiczbaCyfr - 1 - i)*(num % 10);
		num = num / 10;
	}
	return k;
}

int main() {
	int test = 0;
	int input = 0;
	int count = 0;
	cin >> test;
	for (int i = 0; i < test; i++){
		cin >> input;
		int countOfSum = 0;
		while (!checkIsPalindrom(input)){
			input += reverse(input);
			count++;
		}
		cout << input << " " << count << endl;
		count = 0;
	}

	return 0;
}
1
#include <iostream>
#include <string>
using namespace std;

void process(int number)
{
	int count = 0;
	string str = to_string(number);
	string rev(rbegin(str), rend(str));

	while (str != rev)
	{
		number += stoi(rev);
		++count;
		str = to_string(number);
		rev = string(rbegin(str), rend(str));
	}
	
	cout << number << " " << count << endl;
}

int main() 
{
	int sets, number;
	cin >> sets;
	for (int i = 0; i < sets; ++i)
	{
		cin >> number;
		process(number);
	}
	
	return 0;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1