
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- Find uncommon characters of the two strings in C++ Program
- C++ program to find uncommon characters in two given strings
- Finding and returning uncommon characters between two strings in JavaScript
- Python program to find uncommon words from two Strings
- Count common characters in two strings in C++
- Find the uncommon values concatenated from both the strings in Java
- Print common characters of two Strings in alphabetical order in C++
- Concatenated string with uncommon characters in Python?
- Concatenated string with uncommon characters in Python program
- Program to find uncommon elements in two arrays - JavaScript
- Golang Program to find the uncommon elements from two arrays
- Count ways to place all the characters of two given strings alternately
- Python code to print common characters of two Strings in alphabetical order
- Java code to print common characters of two Strings in alphabetical order
- Program to equal two strings of same length by swapping characters in Python

Advertisements