Skip to content

Commit

Permalink
[3강] 문제집
Browse files Browse the repository at this point in the history
  • Loading branch information
Haeun-Y authored Mar 30, 2022
1 parent e7ae700 commit f5aedb0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 윤하은/[3강] 배열/1919.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//220330
//백준 1919번 애너그램만들기 문제 (브론즈 2)
//boj.kr/1919

#include <bits/stdc++.h>
using namespace std;
const int NUM_OF_ALPHABETS(26);
vector<int> charCompositionStr1;
vector<int> charCompositionStr2;

void InitailizeVector(vector<int> &target)
{
const int NUM_OF_ALPHABETS = 26;
target = vector<int>(NUM_OF_ALPHABETS);

return;
}
void assignCharComposition(vector<int> &v, string& target)
{
for(int i =0; i<target.length(); i++)
v[target[i]-97]++;

return;
}
void InputString(string &str1, string &str2)
{
cin >> str1 >> str2;
return;
}
int checkDifferentChar(string &str1, string& str2)
{
int dif =0;
for(int i =0; i<NUM_OF_ALPHABETS; i++)
dif += abs(charCompositionStr1[i] - charCompositionStr2[i]);

return dif;
}
int makeAnagram(string& str1, string& str2)
{
InitailizeVector(charCompositionStr1);
InitailizeVector(charCompositionStr2);

assignCharComposition(charCompositionStr1, str1);
assignCharComposition(charCompositionStr2, str2);

return checkDifferentChar(str1, str2);

}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);

string str1;
string str2;

InputString(str1, str2);
cout << makeAnagram(str1, str2);

}

0 comments on commit f5aedb0

Please sign in to comment.