Как узнать, является ли число палиндромом без математики?

Ошибка типа scala может быть вызвана отсутствием импорта.

Попробуйте добавить к вашему коду следующее:

import io.gatling.http.request._

Вам также может потребоваться добавить import io.gatling.commons.stats._ для Статус, если у вас его еще нет

1
задан iggykimi 18 January 2019 в 22:57
поделиться

2 ответа

Гораздо проще, если вы правильно используете индекс массива в цикле:

// Num is the number to check
// Supposing we are using namespace std
string numString = to_string(num);
bool palindrome = true;
int index = 0;
while(index < numString.size() && palindrome){
   palindrome = numString[index] == numString[numString.size() - index - 1];
   index++;
}
if(palindrome)
   cout << num << " is a palindrome \n"; // line break included
else
   cout << num << " is not a palindrome \n"; // line break included
0
ответ дан Inma 18 January 2019 в 22:57
поделиться

Используйте этот код: -

//num is the Number to check
//Converting int to String
ostringstream ss;
ss<<num;
string snum = ss.str();
string fromfront="", fromback="";
fromfront = snum;
string character;
for(int i=snum.length();i>0;i--)
{
    if(i>0)
        character = snum.substr(i-1, 1);
    fromback+=character;
}
if(fromfront==fromback)
    cout<<endl<<"It is a palindrome.";
else
    cout<<endl<<"It is not a palindrome.";
0
ответ дан GameChanger 18 January 2019 в 22:57
поделиться
Другие вопросы по тегам:

Похожие вопросы: