Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <stdlib.h> /* strtold */
- using namespace std;
- #define TIPO unsigned long long
- /*************************************************************/
- class tiddy{
- public:
- tiddy();
- void lectura ();
- private:
- int T ;//numero de lineas
- void write(int counter,TIPO number);//cout
- TIPO lastTatiana(TIPO number);
- bool isTiddy(TIPO numero); //anterior > actual ? Tiddy
- };
- /*************************************************************/
- tiddy::tiddy():T(-1) {};
- /*************************************************************/
- void tiddy::lectura(){
- int counter(1);
- TIPO ligne;
- cin >>T;//Lee numero de lineas
- //T=stoi (ligne);// 1a. linea numero de lineas
- while (!cin.eof() && counter<=T ){//Read input file
- cin>>ligne;//lectura una linea
- cout <<"linea "<<ligne<<endl;
- //if (!ligne.empty() ){ write (counter++,lastTatiana(stoi(ligne) ) ) ;}//Escribe linea
- write (counter++,lastTatiana( ligne )) ;
- }
- }
- /*************************************************************/
- void tiddy::write(int counter,TIPO number){
- cout << "Case #" << counter << ": " << number<< endl;
- }
- /*************************************************************/
- //Es muy lento por tecnica de fuerza bruta para numeros grandes
- //https://www.geeksforgeeks.org/find-closest-smaller-tidy-number/
- // if string violates tidy property, then
- // decrease the value stored at that index by 1
- // and replace all the value stored right to
- // that index by 9
- /*************************************************************/
- TIPO tiddy::lastTatiana(TIPO number){//lee numero int busca ultimo tiddy
- while (!(isTiddy (number)) ){number--;}
- return number;
- }
- /*************************************************************/
- bool tiddy::isTiddy(TIPO numero){//anterior > actual ? Tiddy
- TIPO actual,anterior(-1);
- do{
- //actual = (numero <10 ? numero : fmod(numero,10));
- actual = (numero <10 ? numero : remainder (numero,10));
- //cout <<"Analisis actual = " <<numero<<endl;//debug
- if (anterior<actual && ! (anterior<0)){ return false;}//No es tiddy
- anterior=actual;
- numero/=10;
- }while (numero>0);
- return true;
- }
- /*************************************************************/
- /*************************************************************/
- int main ( int argc, char *argv[]){
- tiddy test ;
- test.lectura();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement