1번문제 

#include <stdio.h>
int sum(int num);
 
int main(void)
{
    int num;
 
   
    scanf_s("%d", &num);
 
    printf("%d", sum(num));
    return 0;
}
 
int sum(int num)
{
    if (num == 0)
        return 0;
    else if (num > 0)
        return num + sum(num - 1);
}

 

2번문제

#include <iostream>
using namespace std;

int pow(int a, int n) {
    if (n == 0)
        return 1;
    else
        return a * pow(a, n - 1);
}

int main() {
    int a, n;

    cout << "a: ";
    cin >> a;

    cout << "n: ";
    cin >> n;

    cout << "결과: " << pow(a, n) << endl;

    return 0;
}

 

3번 문제

#include <iostream>
#include<string>
#include<algorithm>

using namespace std;




int main()
{
	string n;
	
	cin>>n;
	
	reverse(n.begin(), n.end());
	
	 cout<<"문자열뒤집기"<<n<<endl;


	
	
	return 0;
}

4번 문제

#include <iostream>
#include <algorithm>
#include <vector> 
using namespace std;



void permute(string input, string current = "") {
    if (input.empty()) {
       cout << current << endl;
    } else {
        for (size_t i = 0; i < input.length(); ++i) {
            string remaining = input.substr(0, i) + input.substr(i + 1); // 0부터 i까지 출력 i다음까지 출력 합친다 
            
            
            permute(remaining, current + input[i]);//  순열 한것을 반복해서 출력한다 
        }
    }
}

int main() {
   string word;
    cout << "순열을 구할 문자열을 입력하세요: ";
    cin >> word;

    permute(word);

    return 0;
}

 

https://cafe.naver.com/dremdeveloper

 

매일 알고리즘 : 네이버 카페

공부하면서 필요한 내용을 정리하고 있어요, 코딩테스트 알고리즘 자료구조 개발 C언어 Cpp 디자인패턴

cafe.naver.com

 

https://open.kakao.com/o/gX0WnTCf

 

<코딩 테스트 합격자 되기>(파이썬 편) - 저자방

 

open.kakao.com

 

'개발 공부' 카테고리의 다른 글

코딩테스트 합격자 되자 4주차 과제  (0) 2024.01.02