이 튜토리얼에서는 두 문자열의 흔하지 않은 문자를 찾는 프로그램에 대해 설명합니다.
이를 위해 두 개의 문자열이 제공됩니다. 우리의 임무는 두 문자열의 흔하지 않은 문자를 정렬된 순서로 인쇄하는 것입니다.
예시
#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;
} 출력
a l n p r s u