یہ کیسے چیک کیا جائے کہ دو تار ایک دوسرے کے انگرام ہیں۔

یہ کیسے چیک کیا جائے کہ دو تار ایک دوسرے کے انگرام ہیں۔

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





مسئلہ یہ بیان

آپ کو دو ڈور s1 اور s2 دیے گئے ہیں ، آپ کو یہ چیک کرنے کی ضرورت ہے کہ آیا دونوں ڈور ایک دوسرے کے اینگرام ہیں یا نہیں۔





مثال 1۔ : s1 = 'creative' اور s2 = 'reactive' ہونے دیں۔





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

مثال 2۔ : s1 = 'Peter Piper picked a peck of pickled peppers' and s2 = 'a peck of pickled peppers Peter Piper picked'.



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

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

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





  1. دونوں تاروں کی لمبائی کا موازنہ کریں۔
  2. اگر دونوں ڈوروں کی لمبائی ایک جیسی نہیں ہے ، تو اس کا مطلب ہے کہ وہ ایک دوسرے کے اینگرام نہیں ہو سکتے۔ اس طرح ، جھوٹے کو لوٹائیں۔
  3. اگر دونوں ڈوروں کی لمبائی یکساں ہے تو آگے بڑھیں۔
  4. دونوں تاروں کو ترتیب دیں۔
  5. دونوں ترتیب شدہ ڈوروں کا موازنہ کریں۔
  6. اگر دونوں ترتیب شدہ ڈور ایک جیسے ہیں ، تو اس کا مطلب یہ ہے کہ وہ ایک دوسرے کے انگرام ہیں۔ اس طرح ، سچ لوٹیں۔
  7. اگر دونوں ترتیب شدہ ڈور مختلف ہیں ، تو اس کا مطلب ہے کہ وہ ایک دوسرے کے انگرام نہیں ہیں۔ اس طرح ، جھوٹے کو لوٹائیں۔

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

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

ذیل میں C ++ پروگرام یہ چیک کرنے کے لیے ہے کہ آیا دو تار ایک دوسرے کے انگرام ہیں یا نہیں:





#include
using namespace std;
bool checkAnagrams(string s1, string s2)
{
int size1 = s1.length();
int size2 = s2.length();
// If the length of both strings are not the same,
// it means they can't be anagrams of each other.
// Thus, return false.
if (size1 != size2)
{
return false;
}
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
for (int i = 0; i {
if (s1[i] != s2[i])
{
return false;
}
}
return true;
}
int main()
{
string s1 = 'listen';
string s2 = 'silent';
cout << 'String 1: ' << s1 << endl;
cout << 'String 2: ' << s2 << endl;
if(checkAnagrams(s1, s2))
{
cout << 'Yes, the two strings are anagrams of each other' << endl;
}
else
{
cout << 'No, the two strings are not anagrams of each other' << endl;
}
string s3 = 'Welcome to MUO';
string s4 = 'MUO to Welcome';
cout << 'String 3: ' << s3 << endl;
cout << 'String 4: ' << s4 << endl;
if(checkAnagrams(s3, s4))
{
cout << 'Yes, the two strings are anagrams of each other' << endl;
}
else
{
cout << 'No, the two strings are not anagrams of each other' << endl;
}
string s5 = 'Peter Piper picked a peck of pickled peppers';
string s6 = 'A peck of pickled peppers Peter Piper picked';
cout << 'String 5: ' << s5 << endl;
cout << 'String 6: ' << s6 << endl;
if(checkAnagrams(s5, s6))
{
cout << 'Yes, the two strings are anagrams of each other' << endl;
}
else
{
cout << 'No, the two strings are not anagrams of each other' << endl;
}
string s7 = 'She sells seashells by the seashore';
string s8 = 'seashells by the seashore';
cout << 'String 7: ' << s7 << endl;
cout << 'String 8: ' << s8 << endl;
if(checkAnagrams(s7, s8))
{
cout << 'Yes, the two strings are anagrams of each other' << endl;
}
else
{
cout << 'No, the two strings are not anagrams of each other' << endl;
}
string s9 = 'creative';
string s10 = 'reactive';
cout << 'String 9: ' << s9 << endl;
cout << 'String 10: ' << s10 << endl;
if(checkAnagrams(s9, s10))
{
cout << 'Yes, the two strings are anagrams of each other' << endl;
}
else
{
cout << 'No, the two strings are not anagrams of each other' << endl;
}
return 0;
}

آؤٹ پٹ:

String 1: listen
String 2: silent
Yes, the two strings are anagrams of each other
String 3: Welcome to MUO
String 4: MUO to Welcome
Yes, the two strings are anagrams of each other
String 5: Peter Piper picked a peck of pickled peppers
String 6: A peck of pickled peppers Peter Piper picked
No, the two strings are not anagrams of each other
String 7: She sells seashells by the seashore
String 8: seashells by the seashore
No, the two strings are not anagrams of each other
String 9: creative
String 10: reactive
Yes, the two strings are anagrams of each other

متعلقہ: ایک سٹرنگ میں دیئے گئے کریکٹر کے واقعات کا شمار کیسے کریں

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

ذیل میں ازگر کا پروگرام یہ چیک کرنے کے لیے ہے کہ آیا دو ڈور ایک دوسرے کے انگرام ہیں یا نہیں:

def checkAnagrams(s1, s2):
size1 = len(s1)
size2 = len(s2)
# If the length of both strings are not the same,
# it means they can't be anagrams of each other.
# Thus, return false.
if size1 != size2:
return 0
s1 = sorted(s1)
s2 = sorted(s2)
for i in range(0, size1):
if s1[i] != s2[i]:
return False
return True

s1 = 'listen'
s2 = 'silent'
print('String 1: ', s1)
print('String 2: ', s2)
if(checkAnagrams(s1, s2)):
print('Yes, the two strings are anagrams of each other')
else:
print('No, the two strings are not anagrams of each other')
s3 = 'Welcome to MUO'
s4 = 'MUO to Welcome'
print('String 3: ', s3)
print('String 4: ', s4)
if(checkAnagrams(s3, s4)):
print('Yes, the two strings are anagrams of each other')
else:
print('No, the two strings are not anagrams of each other')
s5 = 'Peter Piper picked a peck of pickled peppers'
s6 = 'A peck of pickled peppers Peter Piper picked'
print('String 5: ', s5)
print('String 6: ', s6)
if(checkAnagrams(s5, s6)):
print('Yes, the two strings are anagrams of each other')
else:
print('No, the two strings are not anagrams of each other')
s7 = 'She sells seashells by the seashore'
s8 = 'seashells by the seashore'
print('String 7: ', s7)
print('String 8: ', s8)
if(checkAnagrams(s7, s8)):
print('Yes, the two strings are anagrams of each other')
else:
print('No, the two strings are not anagrams of each other')
s9 = 'creative'
s10 = 'reactive'
print('String 9: ', s9)
print('String 10: ', s10)
if(checkAnagrams(s9, s10)):
print('Yes, the two strings are anagrams of each other')
else:
print('No, the two strings are not anagrams of each other')

آؤٹ پٹ:

String 1: listen
String 2: silent
Yes, the two strings are anagrams of each other
String 3: Welcome to MUO
String 4: MUO to Welcome
Yes, the two strings are anagrams of each other
String 5: Peter Piper picked a peck of pickled peppers
String 6: A peck of pickled peppers Peter Piper picked
No, the two strings are not anagrams of each other
String 7: She sells seashells by the seashore
String 8: seashells by the seashore
No, the two strings are not anagrams of each other
String 9: creative
String 10: reactive
Yes, the two strings are anagrams of each other

متعلقہ: ایک حرف میں حروف ، حروف ، ہندسے اور خاص حروف کیسے تلاش کریں۔

چیک کریں کہ جاوا اسکرپٹ میں دو سٹرنگز ایک دوسرے کے اینگرام ہیں۔

ذیل میں جاوا اسکرپٹ پروگرام ہے تاکہ یہ چیک کیا جا سکے کہ دو ڈور ایک دوسرے کے اینگرام ہیں یا نہیں:

function checkAnagrams(s1, s2) {
let size1 = s1.length;
let size2 = s2.length;
// If the length of both strings are not the same,
// it means they can't be anagrams of each other.
// Thus, return false.
if (size1 != size2)
{
return false;
}
s1.sort();
s2.sort();
for (let i = 0; i {
if (s1[i] != s2[i])
{
return false;
}
}
return true;
}

var s1 = 'listen';
var s2 = 'silent';
document.write('String 1: ' + s1 + '
');
document.write('String 2: ' + s2 + '
');
if(checkAnagrams(s1.split(''), s2.split(''))) {
document.write('Yes, the two strings are anagrams of each other' + '
');
} else {
document.write('No, the two strings are not anagrams of each other' + '
');
}
var s3 = 'Welcome to MUO';
var s4 = 'MUO to Welcome';
document.write('String 3: ' + s3 + '
');
document.write('String 4: ' + s4 + '
');
if(checkAnagrams(s3.split(''), s4.split(''))) {
document.write('Yes, the two strings are anagrams of each other' + '
');
} else {
document.write('No, the two strings are not anagrams of each other' + '
');
}
var s5 = 'Peter Piper picked a peck of pickled peppers';
var s6 = 'A peck of pickled peppers Peter Piper picked';
document.write('String 5: ' + s5 + '
');
document.write('String 6: ' + s6 + '
');
if(checkAnagrams(s5.split(''), s6.split(''))) {
document.write('Yes, the two strings are anagrams of each other' + '
');
} else {
document.write('No, the two strings are not anagrams of each other' + '
');
}
var s7 = 'She sells seashells by the seashore';
var s8 = 'seashells by the seashore';
document.write('String 7: ' + s7 + '
');
document.write('String 8: ' + s8 + '
');
if(checkAnagrams(s7.split(''), s8.split(''))) {
document.write('Yes, the two strings are anagrams of each other' + '
');
} else {
document.write('No, the two strings are not anagrams of each other' + '
');
}
var s9 = 'creative';
var s10 = 'reactive';
document.write('String 9: ' + s9 + '
');
document.write('String 10: ' + s10 + '
');
if(checkAnagrams(s9.split(''), s10.split(''))) {
document.write('Yes, the two strings are anagrams of each other' + '
');
} else {
document.write('No, the two strings are not anagrams of each other' + '
');
}

آؤٹ پٹ:

String 1: listen
String 2: silent
Yes, the two strings are anagrams of each other
String 3: Welcome to MUO
String 4: MUO to Welcome
Yes, the two strings are anagrams of each other
String 5: Peter Piper picked a peck of pickled peppers
String 6: A peck of pickled peppers Peter Piper picked
No, the two strings are not anagrams of each other
String 7: She sells seashells by the seashore
String 8: seashells by the seashore
No, the two strings are not anagrams of each other
String 9: creative
String 10: reactive
Yes, the two strings are anagrams of each other

متعلقہ: آپ کسی کردار کی ASCII قدر کیسے تلاش کرتے ہیں؟

کوڈ سیکھنے کے لیے صحیح وسائل استعمال کریں۔

اگر آپ اپنی کوڈنگ کی مہارت کو مستحکم کرنا چاہتے ہیں تو ، نئے تصورات کو سیکھنا اور ان کا استعمال کرتے ہوئے وقت گزارنا ضروری ہے۔ ایسا کرنے کا ایک طریقہ پروگرامنگ ایپس کا ہے ، جو آپ کو ایک ہی وقت میں تفریح ​​کرتے ہوئے مختلف پروگرامنگ تصورات سیکھنے میں مدد دے گا۔

بانٹیں بانٹیں ٹویٹ ای میل۔ بین الاقوامی پروگرامرز ڈے کے لیے کوڈ سیکھنے میں آپ کی مدد کے لیے 8 ایپس

اپنی کوڈنگ کی مہارت کو بڑھانا چاہتے ہیں؟ یہ ایپس اور ویب سائٹس آپ کو اپنی رفتار سے پروگرامنگ سیکھنے میں مدد دیں گی۔

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

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

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

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

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

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