یہ کیسے چیک کریں کہ سٹرنگ پالینڈوم ہے

یہ کیسے چیک کریں کہ سٹرنگ پالینڈوم ہے

ایک سٹرنگ کو پالینڈروم کہا جاتا ہے اگر اصل ڈور اور اس کا ریورس ایک جیسا ہو۔ اس آرٹیکل میں ، آپ الگورتھم کے بارے میں سیکھیں گے تاکہ یہ معلوم کیا جا سکے کہ دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔ آپ یہ بھی سیکھیں گے کہ اس الگورتھم کو C ++ ، Python ، C ، اور JavaScript جیسی مقبول ترین پروگرامنگ زبانوں میں کیسے نافذ کیا جائے۔





Palindrome String کی مثالیں۔

ذیل میں palindrome اور غیر palindrome ڈور کی کچھ مثالیں ہیں:





اس بات کا تعین کرنے کے لیے الگورتھم کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔

الگورتھم صرف ہدایات کا ایک سلسلہ ہے جس پر عمل کیا جاتا ہے ، قدم بہ قدم ، کوئی مفید کام کرنے یا کسی مسئلے کو حل کرنے کے لیے۔ آپ مندرجہ ذیل الگورتھم کا استعمال کرتے ہوئے سٹرنگ پالینڈوم کا مسئلہ حل کرسکتے ہیں۔





  1. ایک فنکشن کا اعلان کریں جو دی گئی تار کو پیرامیٹر کے طور پر قبول کرتا ہے۔
  2. ایک بولین متغیر بنائیں اور اسے سچ پر سیٹ کریں۔ متغیر ہونے دیں۔ جھنڈا .
  3. دی گئی تار کی لمبائی معلوم کریں۔ لمبائی رہنے دو۔ n .
  4. دی گئی سٹرنگ کو لوئر کیس میں تبدیل کریں تاکہ حروف کیس کے مابین موازنہ کیا جا سکے۔
  5. کم انڈیکس متغیر کو بطور شروع کریں۔ کم اور اسے 0 پر سیٹ کریں۔
  6. ہائی انڈیکس متغیر کو بطور شروع کریں۔ اعلی اور اسے n-1 پر سیٹ کریں۔
  7. کم سے کم کے دوران درج ذیل کام کریں:
    • کم انڈیکس اور ہائی انڈیکس پر حروف کا موازنہ کریں۔
    • اگر حروف مماثل نہیں ہیں تو ، جھنڈے کو جھوٹے پر سیٹ کریں اور لوپ کو توڑ دیں۔
    • کم کی قیمت میں 1 اضافہ اور اعلی کی قدر میں 1 کی کمی۔
  8. اگر فنکشن کے اختتام پر جھنڈا سچ ہے تو ، اس سے ظاہر ہوتا ہے کہ دی گئی سٹرنگ پیلیندوم ہے۔
  9. اگر فنکشن کے اختتام پر جھنڈا جھوٹا ہے تو یہ اس بات کی نشاندہی کرتا ہے کہ دی گئی سٹرنگ پالینڈروم نہیں ہے۔

C ++ پروگرام چیک کرنے کے لیے کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔

ذیل میں C ++ عمل درآمد ہے اس بات کا تعین کرنے کے لیے کہ دی گئی سٹرنگ پالینڈوم ہے یا نہیں:

گوگل بیک اپ اور سنک کو انسٹال کرنے کا طریقہ
// Including libraries
#include
using namespace std;
// Function to check string palindrome
void checkPalindrome(string str)
{
// Flag to check if the given string is a palindrome
bool flag = true;

// Finding the length of the string
int n = str.length();

// Converting the string to lowercase
for(int i = 0; i {
str[i] = tolower(str[i]);
}

// Initializing low index variable
int low = 0;

// Initializing high index variable
int high = n-1;

// Running the loop until high is greater than low
while (high > low)
{
// If the characters are not same, set the flag to false
// and break from the loop
if(str[high] != str[low])
{
flag = false;
break;
}

// Increment the low index variable
low++;

// Decrement the high index variable
high--;
}

// Check if flag is true or false
if (flag)
{
cout << 'Yes, the given string is a palindrome' << endl;
}
else
{
cout << 'No, the given string is not a palindrome' << endl;
}

return;

}
int main()
{
// Test case: 1
string str1 = 'MUO';
checkPalindrome(str1);

// Test case: 2
string str2 = 'madam';
checkPalindrome(str2);

// Test case: 3
string str3 = 'MAKEUSEOF';
checkPalindrome(str3);

// Test case: 4
string str4 = 'racecar';
checkPalindrome(str4);

// Test case: 5
string str5 = 'mom';
checkPalindrome(str5);

return 0;
}

آؤٹ پٹ:



No, the given string is not a palindrome
Yes, the given string is a palindrome
No, the given string is not a palindrome
Yes, the given string is a palindrome
Yes, the given string is a palindrome

ازگر کا پروگرام چیک کرنے کے لیے کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔

ذیل میں ازگر کا نفاذ ہے اس بات کا تعین کرنے کے لیے کہ دی گئی سٹرنگ پالینڈوم ہے یا نہیں:

# Function to check string palindrome
def checkPalindrome(str):
# Flag to check if the given string is a palindrome
flag = True
# Finding the length of the string
n = len(str)
# Converting the string to lowercase
str = str.lower()
# Initializing low index variable
low = 0
# Initializing high index variable
high = n-1
# Running the loop until high is greater than low
while high > low:
# If the characters are not same, set the flag to false
# and break from the loop
if str[high] != str[low]:
flag = False
break
# Increment the low index variable
low = low + 1
# Decrement the high index variable
high = high - 1
# Check if flag is true or false
if flag:
print('Yes, the given string is a palindrome')
else:
print('No, the given string is not a palindrome')
# Test case: 1
str1 = 'MUO'
checkPalindrome(str1)
# Test case: 2
str2 = 'madam'
checkPalindrome(str2)
# Test case: 3
str3 = 'MAKEUSEOF'
checkPalindrome(str3)
# Test case: 4
str4 = 'racecar'
checkPalindrome(str4)
# Test case: 5
str5 = 'mom'
checkPalindrome(str5)

آؤٹ پٹ:





No, the given string is not a palindrome
Yes, the given string is a palindrome
No, the given string is not a palindrome
Yes, the given string is a palindrome
Yes, the given string is a palindrome

سی پروگرام چیک کرنے کے لیے کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔

ذیل میں C کا نفاذ ہے اس بات کا تعین کرنے کے لیے کہ آیا دی گئی سٹرنگ palindrome ہے یا نہیں:

// Including libraries
#include
#include
#include
#include
// Function to check string palindrome
void checkPalindrome(char str[])
{
// Flag to check if the given string is a palindrome
bool flag = true;
// Finding the length of the string
int n = strlen(str);
// Converting the string to lowercase
for(int i = 0; i {
str[i] = tolower(str[i]);
}
// Initializing low index variable
int low = 0;
// Initializing high index variable
int high = n-1;
// Running the loop until high is greater than low
while (high > low)
{
// If the characters are not same, set the flag to false
// and break from the loop
if(str[high] != str[low])
{
flag = false;
break;
}
// Increment the low index variable
low++;
// Decrement the high index variable
high--;
}
// Check if flag is true or false
if (flag)
{
printf('Yes, the given string is a palindrome ⁠n');
}
else
{
printf('No, the given string is not a palindrome ⁠n');
}
return;
}
int main()
{
// Test case: 1
char str1[] = 'MUO';
checkPalindrome(str1);
// Test case: 2
char str2[] = 'madam';
checkPalindrome(str2);
// Test case: 3
char str3[] = 'MAKEUSEOF';
checkPalindrome(str3);
// Test case: 4
char str4[] = 'racecar';
checkPalindrome(str4);
// Test case: 5
char str5[] = 'mom';
checkPalindrome(str5);
return 0;
}

آؤٹ پٹ:





آن لائن کسی بھی سائٹ سے کوئی بھی ویڈیو مفت ڈاؤن لوڈ کریں۔
No, the given string is not a palindrome
Yes, the given string is a palindrome
No, the given string is not a palindrome
Yes, the given string is a palindrome
Yes, the given string is a palindrome

جاوا اسکرپٹ پروگرام چیک کرنے کے لیے کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں۔

ذیل میں جاوا اسکرپٹ کا نفاذ ہے اس بات کا تعین کرنے کے لیے کہ آیا دی گئی سٹرنگ پالینڈوم ہے یا نہیں:

// Function to check string palindrome
function checkPalindrome(str) {
// Flag to check if the given string is a palindrome
var flag = true;
// Finding the length of the string
var n = str.length;
// Converting the string to lowercase
str = str.toLowerCase();
// Initializing low index variable
var low = 0;
// Initializing high index variable
var high = n-1;
// Running the loop until high is greater than low
while (high > low) {
// If the characters are not same, set the flag to false
// and break from the loop
if(str[high] != str[low]) {
flag = false;
break;
}
// Increment the low index variable
low++;
// Decrement the high index variable
high--;
}
// Check if flag is true or false
if (flag) {
console.log('Yes, the given string is a palindrome');
} else {
console.log('No, the given string is not a palindrome');
}
}
// Test case: 1
var str1 = 'MUO';
checkPalindrome(str1);
// Test case: 2
var str2 = 'madam';
checkPalindrome(str2);
// Test case: 3
var str3 = 'MAKEUSEOF';
checkPalindrome(str3);
// Test case: 4
var str4 = 'racecar';
checkPalindrome(str4);
// Test case: 5
var str5 = 'mom';
checkPalindrome(str5);

آؤٹ پٹ:

No, the given string is not a palindrome
Yes, the given string is a palindrome
No, the given string is not a palindrome
Yes, the given string is a palindrome
Yes, the given string is a palindrome

پروگرامنگ میں سٹرنگ سے نمٹنے کا طریقہ سیکھیں۔

ڈور کے ساتھ کام کرنا پروگرامنگ کا ایک لازمی حصہ ہے۔ آپ کو معلوم ہونا چاہیے کہ کسی بھی پروگرامنگ زبانوں جیسے کہ ازگر ، جاوا اسکرپٹ ، C ++ ، وغیرہ میں ڈور کو استعمال اور جوڑ توڑ کرنا ہے۔

اگر آپ شروع کرنے کے لیے کسی زبان کی تلاش کر رہے ہیں تو ازگر ایک بہترین انتخاب ہے۔

بانٹیں بانٹیں ٹویٹ ای میل۔ ازگر سیکھنا؟ اسٹرنگز کو جوڑنے کا طریقہ یہاں ہے۔

ازگر میں ڈوروں کا استعمال اور جوڑ توڑ مشکل دکھائی دیتا ہے ، لیکن یہ دھوکہ دہی سے سیدھا ہے۔

اگلا پڑھیں۔
متعلقہ موضوعات۔
  • پروگرامنگ۔
  • کوڈنگ ٹیوٹوریل
مصنف کے بارے میں یوراج چندر۔(60 مضامین شائع ہوئے)

یوراج دہلی یونیورسٹی ، انڈیا میں کمپیوٹر سائنس کے انڈر گریجویٹ طالب علم ہیں۔ وہ فل اسٹیک ویب ڈویلپمنٹ کے بارے میں پرجوش ہے۔ جب وہ نہیں لکھ رہا ہے ، وہ مختلف ٹیکنالوجیز کی گہرائی کو تلاش کر رہا ہے۔

یوراج چندر سے مزید

ہماری نیوز لیٹر کو سبسکرائب کریں

ٹیک ٹپس ، جائزے ، مفت ای بکس ، اور خصوصی سودوں کے لیے ہمارے نیوز لیٹر میں شامل ہوں!

سبسکرائب کرنے کے لیے یہاں کلک کریں۔