Kaprekar numbers: Difference between revisions

m (whitespace)
Line 64:
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <utility>
 
std::pair<std::string, std::string>long splitStringstring2long( const std::string & s ,) {
long result ;
int pos ) {
return std::make_pairistringstream( s.substr( 0 , pos ) ,>> s.substr( pos ) )result ;
return result ;
}
 
Line 80:
std::string numberstring = numberbuf.str( ) ;
for ( int i = 0 ; i < numberstring.length( ) ; i++ ) {
std::pair<std::string firstpart = numberstring.substr( 0 , std::string>i stringparts) =,
secondpart = numberstring.substr( i ) ;
splitString( numberstring , i ) ;
//we do not accept figures ending in a sequence of zeroes
if ( stringparts.secondsecondpart.find_first_not_of( "0" ) == std::string::npos ) {
return false ;
}
if ( atolstring2long( stringparts.first.c_strfirstpart ) + string2long( secondpart ) == number ) {
+ atol( stringparts.second.c_str( )) == number ) {
return true ;
}
Anonymous user