Zadanie Spoj BFN1

0

Witam,
Problem jest następujący, program po obliczeniu wypisuje pierwszy wynik nieskończoność (w testach bez vectorów z wypisywaniem wyniku in time zamiast po wczytaniu liczb a następnie wypisaniu ich wynik był poprawny). Kod do zadania - http://pl.spoj.com/problems/BFN1/

 
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int inverted(int word)
{
	string upturned;
	
	ostringstream ss;
	ss << word;
	string test = ss.str();

	int extent = test.size(), upturned_number;

	for (int i = 0; i < extent; i++)
	{
		upturned += test[extent-i-1];
	}

	istringstream iss(upturned);
	iss >> upturned_number;

	return upturned_number;
}

int main()
{
	short int value;
	int amount;
	vector<int> tab;

	cin >> value;

	for (int i = 0; i < value; i++)
	{
		cin >> amount;
		if (amount < 10)
		{
			tab.push_back(amount);
			tab.push_back(0);

		}
		else 
		{
			switch(amount)
			{
				case 11:
				case 22:
				case 33:
				case 44:
				case 55:
				case 66:
				case 77:
					tab.push_back(amount);
					tab.push_back(0);
				break;
				default:		// change to palindrom
				{
					short int pointer = 0, sum = 0;

					do
					{
						int vtest = inverted(amount);

						sum = amount + vtest;
						pointer++;

						if(sum == inverted(sum))
						{
							tab.push_back(sum);
							tab.push_back(pointer);
							break;
						}
						amount = sum;
					}
					while(true);

				}
			}

		}

	}
	for (int i = 0; i < (value*2); i+2)
		cout << tab[i] << " " << tab[i+1] << endl;

	return 0;
}
0

A wystarczy tyle:

#include <cstdio>
using namespace std;

int main()
  {
   unsigned t,val,cnt;
   for(scanf("%u",&t);t--;printf("%u %u\n",val,cnt))
     {
      for(cnt=0,scanf("%u",&val);;++cnt)
        {
         unsigned wal=0,sv;
         for(unsigned v=val;(sv=v)!=0;wal=wal*10+sv-10*v) v/=10;
         if(val==wal) break;
         val+=wal;
        }      
     }
   return 0;
  }

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