전체 글 216

[백준] 1764번 : 듣보잡 - C++

문제 http://acmicpc.net/problem/1764 1764번: 듣보잡 첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다. www.acmicpc.net 설명 #include #include #include #include #include #include #include using namespace std; int main() { int N, M; vector hear; vector see; vector answer; cin >> N >> M; for( int i = 0;i> tmp; hear.push_back(tmp); } sort(hear.beg..

카테고리 없음 2022.04.03

[백준] 1181번: 단어정렬 - C++

문제 https://www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net 설명 #include #include #include #include #include using namespace std; bool compare(string a, string b) { if(a.size()==b.size()) { return aN; for(int i = 0; i>tmp; words.push_back(tmp); } sort(words.begin(), words.en..

[C++] 문자열 정리

string 헤더 #include 🌀 선언 및 초기화 예시 //생성과 동시에 초기화 string str1 = "Hello World!"); string str2("Hello World!"); //생성한 후 초기화 string str3; str3 = "Hello World!"; //다른 문자열로 초기화 string str4(str3); 🌀 멤버함수 문자열의 문자 접근 string str = "Hello World!" // 배열처럼 Index로 접근 str[0]; // 'H' 반환. 반환된 문자는 char형 str.at(0); // 'H' 반환. 반환된 문자는 char형 // 맨 앞 문자 반환 str.front(); // 맨 뒤 문자 반환 str.back(); 문자열의 길이 반환 string str = "H..

[백준] 7576번: 토마토(BFS) - C++

https://www.acmicpc.net/problem/7576 7576번: 토마토 첫 줄에는 상자의 크기를 나타내는 두 정수 M,N이 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M,N ≤ 1,000 이다. 둘째 줄부터는 하나의 상자에 저장된 토마토 www.acmicpc.net #include #include using namespace std; int M,N; int map[1000][1000]; queue q; bool result = false; int days[1000][1000]; int day; int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}}; void reset() { for(int y=0;y

카테고리 없음 2022.03.17

[백준] 2606번: 바이러스(DFS) - C++

https://www.acmicpc.net/problem/2606 2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net #include #include using namespace std; int N,T; int map[101][101]; int visited[101]; int result = 0; void reset() { for(int i = 1; i>T; reset(); for(int i = 0;i>n1>>n2; map[n1][n2] = 1; map[n2][n1] = 1; } DFS(1); cout

[백준] 2606번: 바이러스(BFS) - C++

https://www.acmicpc.net/problem/2606 2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net 처음 코드(틀림) #include #include using namespace std; int N,T; int map[101][101]; int visited[101]; int result = 0; queue q; void reset() { for(int i = 1; i>T; reset(); for(int i = 0;i>n1>>n2; map[n1][n2] = 1; } BFS(1); coutn1>>n2;..

[백준] 2667번: 단지번호붙이기(DFS) - C++

https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net #include #include #include #include using namespace std; int N; int map[25][25]; bool visited[25][25]; int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; int num = 1; vector v; void reset() { for(int i=0;iN; reset(); for(int i=0;i>s..

[백준] 2667번: 단지번호붙이기(BFS) - C++

https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net #include #include #include #include using namespace std; int N; int map[25][25]; bool visited[25][25]; int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; queue q; vector v; void reset() { for(int i=0;iN; reset(); for(int i=0;i>s; fo..

[백준] 1012번: 유기농 배추(DFS) - C++

https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net #include #include using namespace std; int M,N,K; int map[50][50]; bool visited[50][50]; int dir[4][2] = {{1,0},{-1,0},{0,-1},{0,1}}; void reset() { for(int y = 0;y>T; for(int i = 0 ;i> M >> N >> K; reset(); for(int k = 0;k>x>>y; ..

[백준] 1012번: 유기농 배추(BFS) - C++

https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net #include #include using namespace std; int M,N,K; int map[50][50]; bool visited[50][50]; queue q; int dir[4][2] = {{1,0},{-1,0},{0,-1},{0,1}}; void reset(int M, int N) { for(int y=0; y < N;y++) for(int x = 0;x < M;x++) { map[y][x]..

반응형