본문 바로가기

programming23

15650 - N과 M (2) 문제 자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. 1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열 고른 수열은 오름차순이어야 한다. 입력 첫째 줄에 자연수 N과 M이 주어진다. (1 ≤ M ≤ N ≤ 8) 출력 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해야 한다. 풀이 재귀를 연습하기 좋다. 두가지 풀이로 풀어보았다. 1. 오름차순이므로 시작하는 부분 재귀함수로 넘겨줘 풀이 #include&ltiostream&gt #include&ltstring&gt #include&ltalgorithm&g.. 2020. 8. 27.
백준 - 1260 dfs와 bfs 알고스팟 사천성을 풀다가.... 탐색 알고리즘을 이용하면 된다고 하길래 풀어봤다 . 알고리즘을 오랜만에 봐서 좀 오래걸렸다. 근데 아직도 사천성은 못풀겠다 ㅎㅎ #include #include #include #include #include #include using namespace std; void dfs(int start, bool decide[], vector &graph); void bfs(int start, bool decide[], vector &graph); int main(){ int n,m,v; int x,y,j; int i; cin >> n >> m >> v; vector graph(n+1, vector()); bool decide[n+1]; f.. 2020. 5. 21.
알고스팟 - 튜토리얼 XHAENEUNG 코드가 좀 난잡하다.... 입력한 숫자와 db를 한자리씩 비교하였다. 여기서 seven같이 같은 문자가 여러개 들어가는 경우가 있어서 찾아진 것은 *로 치환하였다. #include #include #include using namespace std; int main(){ vector to_ten{"zero","one","two","three","four","five","six","seven","eight","nine","ten"}; vector input_result; vector last_result; char con_tmp; string ori=""; string mix=""; string result_tmp=""; char tmp; vector int_ori; vector int_mix; vecto.. 2020. 5. 16.
알고스팟 - 튜토리얼 URI 20분 컷했당 쉽다. #include #include #include using namespace std; int main(){ int num; int i, j; string temp; vector input_string; cin >> num; for(i = 0; i > temp; input_string.push_back(temp); } for(i = 0; i < num; i++){ for(j = 0; j < input_string[i].length(); j++){ if(input_string[i][j] == '%' && input_string[i][j+1] == '2'){ switch (input_string[i][j+2]) { case '0': cout 2020. 5. 15.
알고스팟 - 튜토리얼 HOTSUMMER 븅딱같이 vector 초기화 안해줘서 삽질했다.... int i; int j; int num; int temp; vector input_sum; vector input_temp; vector input; cin >> num; for(i = 0; i > temp; input_sum.push_back(temp); for(j = 0; j > temp; input_temp.push_back(temp); } input.push_back(input_temp); input_temp.clear(); } for(i = 0; i < num; i++){ decide(input_sum[i], input[i]); } } void decide(int input_sum,.. 2020. 5. 15.
알고스팟 - 튜토리얼 mispell 뭐 없다. 쉽다. using namespace std; void sort_func(string origin, int num); int main(){ int i; int num; int input_num; vector input; string temp; vector minus; cin >> num; for(i = 0; i > input_num >> temp; input.push_back(temp); minus.push_back(input_num); } for(i = 0; i < num; i++){ cout 2020. 5. 14.