Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5주차 문제 풀이 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bruteforce/p소수 만들.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <vector>
#include <iostream>
using namespace std;

int abc(int num) {
int count = 0;
for (int i = 2; i <= num; i++) {
if (num % i == 0) {
count++;
}
}
return count;
}

int solution(vector<int> nums) {
int answer = 0;
int num = 0;
for (int i = 0; i < nums.size(); i++) {
for (int j = i + 1; j < nums.size(); j++) {
for (int k = j + 1; k < nums.size(); k++) {
num = nums[i] + nums[j] + nums[k];
int count = abc(num);
if (count == 1) {
answer++;
}
}
}
}

return answer;
}
70 changes: 70 additions & 0 deletions string/p숫자 문자열과 영단어.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <string>
#include <vector>
#include <iostream>
using namespace std;

int solution(string s) {
int answer = 0;
string v;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'z') {
i = i + 3;
v = v + "0";
}
else if (s[i] == 'o') {
i = i + 2;
v = v + "1";
}
else if (s[i] == 't') {
if (s[i + 1] == 'w') {
i = i + 2;
v = v + "2";
}
else if (s[i + 1] == 'h') {
i = i + 4;
v = v + "3";
}
}
else if (s[i] == 'f') {
if (s[i + 1] == 'o') {
i = i + 3;
v = v + "4";
}
else if (s[i + 1] == 'i') {
i = i + 3;
v = v + "5";
}
}
else if (s[i] == 's') {
if (s[i + 1] == 'i') {
i = i + 2;
v = v + "6";
}
else if (s[i + 1] == 'e') {
i = i + 4;
v = v + "7";
}
}
else if (s[i] == 'e') {
i = i + 4;
v = v + "8";
}
else if (s[i] == 'n') {
i = i + 3;
v = v + "9";
}
else {
v = v + s[i];
}
}
answer = stoi(v);
cout << answer;
return answer;
}

int main() {
string s;
cin >> s;
solution(s);
return 0;
}