 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find uncommon characters of the two strings in C++
In this tutorial, we will be discussing a program to find uncommon characters of the two strings.
For this we will be provided with two strings. Our task is to print out the uncommon characters of both strings in sorted order.
Example
#include <bits/stdc++.h> using namespace std; const int LIMIT_CHAR = 26; //finding the uncommon characters 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; }  Output
a l n p r s u
Advertisements
 