palindrome

Mar 29, 2020 at 8:10pm
Write a program to get the number [n] from the user and print the [n]th number palindrome of even length.

input :

Is an integer [n].

1<= n <=1000000

output :

A palindrome number with the desired specification.




input 1

1

output 1

11

input 2

10

output 2

1001

Last edited on Mar 29, 2020 at 8:11pm
Mar 29, 2020 at 8:27pm
What is the question?
Mar 29, 2020 at 8:27pm
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
using namespace std;

int main ()
{
   string n;
   cout << "Enter a number: ";   cin >> n;
   cout << n << string( n.rbegin(), n.rend() ) << '\n';
}

Enter a number: 10
1001
Mar 29, 2020 at 8:37pm
hey thank you lastchance.

with your code i got 0 :


1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
using namespace std;

int main ()
{
   string n;
   cout << "Enter a number: ";   cin >> n;
   cout << n << string( n.rbegin(), n.rend() ) << '\n';
}



Compiled Successfully
Test 1
WRONG ANSWER
Test 2
WRONG ANSWER
Test 3
WRONG ANSWER
Test 4
WRONG ANSWER
Test 5
WRONG ANSWER
Test 6
WRONG ANSWER
Test 7
WRONG ANSWER
Test 8
WRONG ANSWER
Test 9
WRONG ANSWER
Test 10
WRONG ANSWER
Test 11
WRONG ANSWER
Test 12
WRONG ANSWER
Test 13
WRONG ANSWER
Test 14
WRONG ANSWER
Test 15
WRONG ANSWER
Test 16
WRONG ANSWER
Test 17
WRONG ANSWER
Test 18
WRONG ANSWER
Test 19
WRONG ANSWER
Test 20
WRONG ANSWER
Test 21
WRONG ANSWER
Test 22
WRONG ANSWER
Test 23
WRONG ANSWER
Test 24
WRONG ANSWER
Test 25
WRONG ANSWER
Test 26
WRONG ANSWER
Test 27
WRONG ANSWER



i wrote this and it gave me 44 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include<vector> 
#include <algorithm> 
using namespace std;


int main()
{
	string n,m;
	cin >> n;
	m = n;

	if (m.size() % 2 == 0 || m.size() == 1)
	{
		reverse(m.begin(), m.end());
		cout << n << m;
	}
	else if (m.size() % 2 != 0)
	{
		m.resize(m.size() - 1);
		reverse(m.begin(), m.end());
		n.resize(n.size() - 1);

		cout << n << m;
	}
}



Compiled Successfully
Test 1
ACCEPTED
Test 2
ACCEPTED
Test 3
ACCEPTED
Test 4
ACCEPTED
Test 5
WRONG ANSWER
Test 6
ACCEPTED
Test 7
WRONG ANSWER
Test 8
WRONG ANSWER
Test 9
ACCEPTED
Test 10
ACCEPTED
Test 11
ACCEPTED
Test 12
WRONG ANSWER
Test 13
WRONG ANSWER
Test 14
WRONG ANSWER
Test 15
WRONG ANSWER
Test 16
WRONG ANSWER
Test 17
WRONG ANSWER
Test 18
ACCEPTED
Test 19
ACCEPTED
Test 20
ACCEPTED
Test 21
WRONG ANSWER
Test 22
WRONG ANSWER
Test 23
WRONG ANSWER
Test 24
WRONG ANSWER
Test 25
WRONG ANSWER
Test 26
WRONG ANSWER
Test 27
ACCEPTED
Mar 29, 2020 at 8:46pm
i dont know how u come up with these answers but i got to tell you , you are GOOD at this

ty it worked , can u tell me wheres the problem in my code that it didn't work ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include<vector>      // std::vector
#include <algorithm> // std::reverse
using namespace std;


int main()
{
	string n,m;
	cin >> n;
	m = n;

	if (m.size() % 2 == 0 || m.size() == 1)
	{
		reverse(m.begin(), m.end());
		cout << n << m;
	}
	else if (m.size() % 2 != 0)
	{
		m.resize(m.size() - 1);
		reverse(m.begin(), m.end());
		n.resize(n.size() - 1);

		cout << n << m;
	}
}
Mar 29, 2020 at 8:57pm
I don't understand your question. It's open to two interpretations (or I'm dumb). Try both of these.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
using namespace std;

int main()
{
   int n;
   cin >> n;
   for ( int i = 10; ; i *= 100 )
   {
      for ( int j = i; j < 10 * i; j++ )
      {
         string test = to_string( j );
         if ( test == string( test.rbegin(), test.rend() ) )
         {
            n--;
            if ( !n )
            {
               cout << test << '\n';
               return 0;
            }
         }
      }
   }
}

10
1001



1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>
using namespace std;

int main ()
{
   string n;
   cin >> n;
   cout << n << string( n.rbegin(), n.rend() ) << '\n';
}

10
1001
Last edited on Mar 29, 2020 at 8:58pm
Mar 29, 2020 at 9:43pm
hi again .
no you're a genius also as i mentioned your code

string( n.rbegin(), n.rend() )

WORKED GREAT .

i just wanted to now what was the problem in MY code and now i found it . thank you so much for helping , if only i could've been one of your students
Topic archived. No new replies allowed.