U E D R , A S I H C RSS

Reverse And Add/김회영

No older revisions available

No older revisions available



C code

~cpp 
#include<iostream> 
#include<math.h> 
using namespace std; 
 
long inverseDigit(long num); 
bool isCircularLetter(long num); 
 
int main() 
{ 
        
	int testCount=0; 
    cin>>testCount;
        
	long* number=new long[testCount]; 
    int* calCount=new int[testCount];

	int i=0; 
    
	for(i=0;i<testCount;i++) 
		cin>>number[i];
    
    for(i=0;i<testCount;i++) 
    {    
		calCount[i]=0;
		while(!isCircularLetter(number[i]))
		{     
			calCount[i]++;
			number[i]=number[i]+inverseDigit(number[i]);        
		}	
    }
	
	cout<<endl;
	for(i=0;i<testCount;i++) 
          cout<<calCount[i]<<" "<<number[i]<<endl; 
         
        return 0; 
} 
 
long inverseDigit(long num) 
{ 
	
	int arrayOfDigit[10]; 
	int count=-1; 
 
	while(num!=0) 
	{        
		arrayOfDigit[++count]=num%10; 
		num=num/10;      
	} 
         
	long returnValue=0; 
	
	for(int i=count ; i>=0 ; i--) 
		returnValue+=arrayOfDigit[i]*pow(10,count-i); 
	
	return returnValue; 
} 
 
bool isCircularLetter(long num) 
{ 

	int arrayOfDigit[10]; 
	int count=-1; 

	while( num !=0 )//10으로 나눈 나머지가 몇인가?1이상이면  
	{        
		arrayOfDigit[++count]=num%10; 
		num=num/10;      
	} 
 
	int i=0; 
	int j=count; 
         
	while(arrayOfDigit[i]==arrayOfDigit[j]) 
	{ 
		i++; 
		j--; 
		
			if(i>j) 
				return true; 
	} 
	
	return false; 
} 

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:54
Processing time 0.0232 sec