Answers for "stack and queue palindrome c++"

C++
0

next palindrome number in cpp

#include <iostream>
#include <string.h>
using namespace std;
int nextpalin (int num){
    while (num++) {
        string str = to_string (num); /// int to string conversion
        int l = str.length()-1;
        int s = 0;
        while( s<l ){
              if (str[s]!=str[l]) break;
              else {
                    s++;
                    l--;
                    }
        if (s>=l) return num;}
                }
   }

int main () {
    int t;
    cin >> t;
    while (t--){
    int num;
    cin >> num;
    if (num==0)  cout << "1" << endl;
   else { 
       if (num<9)  cout << num+1 << endl;
       else  cout << nextpalin( num) << endl;}
     }
}
Posted by: Guest on February-19-2021
0

how to print nth palindrome number in c++

int n;
    int count =0;
    while(true){
        cin>> n;
        if (n == 0) return 0;
        
        if( n <= 10000){
        for( int i=1 ; i <= 2000000000; i++){

                if( palindrom(i) == true) {
                    count++;
                    //cout << "palindrom : " << i<< " count : " << count <<endl;
                
                
                    if( count == n ) {
                    
                        cout << i <<endl;
                   
                        count =0;
                        break;
                    }
Posted by: Guest on March-12-2020

Browse Popular Code Answers by Language