इस ट्यूटोरियल में, हम दो स्ट्रिंग्स के असामान्य वर्ण खोजने के प्रोग्राम पर चर्चा करेंगे।
इसके लिए हमें दो स्ट्रिंग्स प्रदान की जाएंगी। हमारा कार्य दोनों स्ट्रिंग्स के असामान्य वर्णों को सॉर्टेड क्रम में प्रिंट करना है।
उदाहरण
#include <bits/stdc++.h> using namespace std; const int LIMIT_CHAR = 26; //असामान्य वर्ण खोजना void calculateUncommonCharacters(string str1, string str2) { int isthere[LIMIT_CHAR]; for (int i=0; i<LIMIT_CHAR; i++) isthere[i] = 0; int l1 = str1.size(); int l2 = str2.size(); for (int i=0; i<l1; i++) isthere[str1[i] - 'a'] = 1; for (int i=0; i<l2; i++) { if (isthere[str2[i] - 'a'] == 1 || isthere[str2[i] - 'a'] == -1) isthere[str2[i] - 'a'] = -1; else isthere[str2[i] - 'a'] = 2; } for (int i=0; i<LIMIT_CHAR; i++) if (isthere[i] == 1 || isthere[i] == 2 ) cout << (char(i + 'a')) << " "; } int main() { string str1 = "tutorials"; string str2 = "point"; calculateUncommonCharacters(str1, str2); return 0; } आउटपुट
a l n p r s u