-- 1.Introduction
SELECT name, continent, population FROM world

-- 2.Large Countries
SELECT name FROM world
WHERE population >= 200000000

-- 3.Per capita GDP (1인당 국내 총생산)
SELECT name, GDP/population
FROM world
WHERE population >= 200000000

-- 4.South America In millions
SELECT name, population/1000000
FROM world
WHERE continent='South America'

-- 5.France, Germany, Italy
SELECT name, population
FROM world
WHERE name IN ('France', 'Germany', 'Italy')

-- 6.United
SELECT name
FROM world
WHERE name LIKE '%United%'

-- 7.Two ways to be big
SELECT name, population, area
FROM world
WHERE area >= 3000000 OR population >=250000000

-- 8.One or the other (but not both)
SELECT name, population, area
FROM world
WHERE (area > 3000000 AND population<250000000) OR (area < 3000000 AND population>250000000) 

-- 9.Rounding
SELECT name, ROUND(population/1000000,2), ROUND(gdp/1000000000,2)
FROM world
WHERE continent='South America'

-- 10.Trillion dollar economies
SELECT name, ROUND(gdp/population, -3)
FROM world
WHERE gdp>1000000000000

-- 11.Name and capital have the same length
-- Correct 확인 안됨..
SELECT name, capital 
FROM world 
WHERE LEN(name) = LEN(capital);

-- 12.Matching name and capital
-- <> as the NOT EQUALS
SELECT name, capital
FROM world
WHERE LEFT(name,1)= LEFT(capital,1)
	AND name<>capital

-- 13.All the vowels
SELECT name
  FROM world
WHERE name LIKE '%a%'
  AND name LIKE '%e%'
  AND name LIKE '%i%'
  AND name LIKE '%o%'
  AND name LIKE '%u%'
  AND name NOT LIKE '% %'

'SQL > Sqlzoo' 카테고리의 다른 글

[sqlzoo] SELECT Quiz 정답, 풀이  (0) 2022.07.21
[sqlzoo] SELECT basics 정답, 풀이  (0) 2022.07.21

1. Select the code which produces this table

SELECT name, population
  FROM world
 WHERE population BETWEEN 1000000 AND 1250000

2. Pick the result you would obtain from this code:

3. Select the code which shows the countries that end in A or L

SELECT name FROM world
 WHERE name LIKE '%a' OR name LIKE '%l'

4. Pick the result from the query

5. Here are the first few rows of the world table:

Pick the result you would obtain from this code:

6. Select the code that would show the countries with an area larger than 50000 and a population smaller than 10000000

SELECT name, area, population
  FROM world
 WHERE area > 50000 AND population < 10000000

7. Select the code that shows the population density(인구밀도) of China, Australia, Nigeria and France

SELECT name, population/area
  FROM world
 WHERE name IN ('China', 'Nigeria', 'France', 'Australia')

 

'SQL > Sqlzoo' 카테고리의 다른 글

[sqlzoo] SELECT from WORLD Tutorial 정답, 풀이  (0) 2022.07.21
[sqlzoo] SELECT basics 정답, 풀이  (0) 2022.07.21
-- 1. Introducing the world table of countries

SELECT population FROM world
  WHERE name = 'Germany'
  
-- 2. Scandinavia
  
SELECT name, population FROM world
  WHERE name IN ('Sweden', 'Norway', 'Denmark');
  
-- 3. Just the right size
  
SELECT name, area FROM world
  WHERE area BETWEEN 200000 AND 250000

'SQL > Sqlzoo' 카테고리의 다른 글

[sqlzoo] SELECT from WORLD Tutorial 정답, 풀이  (0) 2022.07.21
[sqlzoo] SELECT Quiz 정답, 풀이  (0) 2022.07.21

https://www.acmicpc.net/problem/2252

 

2252번: 줄 세우기

첫째 줄에 N(1 ≤ N ≤ 32,000), M(1 ≤ M ≤ 100,000)이 주어진다. M은 키를 비교한 회수이다. 다음 M개의 줄에는 키를 비교한 두 학생의 번호 A, B가 주어진다. 이는 학생 A가 학생 B의 앞에 서야 한다는 의

www.acmicpc.net

- PASS

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

using namespace std;

vector<vector<int>> vec;
vector<int> result;
int N, M;
int visit[32001];

void dfs(int num) {
	visit[num] = 1;

    for (auto i : vec[num]) {
        if (visit[i])
            continue;
        dfs(i);
    }

    result.push_back(num);
}

int main() {

    cin >> N >> M;

	vec.resize(N + 1);

    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
		vec[A].push_back(B);
    }

    for (int i = 1; i <= N; i++) {
        if (visit[i]==0)
            dfs(i);
    }

	for (int i = N - 1; i >= 0; i--)
		cout << result[i] << " ";

    return 0;
}

- FAIL

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

using namespace std;

int main() {

	vector<int> row;

	int N, M;

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		int flag = 0;
		for (int j = 0; j < row.size(); j++) {
			if (row[j] == B) {
				row.insert(row.begin() + j, A);
				flag = 1;
				break;
			}
		}

		if (flag == 0) {
			row.push_back(A);
			row.push_back(B);
		}
	}

	for (int i = 0; i < N; i++)
		cout << row[i] << " ";
        
    return 0;
}

'APS > 백준' 카테고리의 다른 글

[1197] 최소 스패닝 트리 C++  (0) 2022.03.15
[5052] 전화번호 목록  (0) 2022.03.15
[21924] 도시 건설 C++  (0) 2022.03.05
[14716] 현수막 C++  (0) 2022.03.05
[10816] 숫자 카드2 C++  (0) 2022.03.03

https://www.acmicpc.net/problem/1197

 

1197번: 최소 스패닝 트리

첫째 줄에 정점의 개수 V(1 ≤ V ≤ 10,000)와 간선의 개수 E(1 ≤ E ≤ 100,000)가 주어진다. 다음 E개의 줄에는 각 간선에 대한 정보를 나타내는 세 정수 A, B, C가 주어진다. 이는 A번 정점과 B번 정점이

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

vector<pair<int, pair<int, int>>> vec;
int boss[10001];

int findBoss(int a) {
	if (boss[a] == a)
		return a;
	else
		return boss[a] = findBoss(boss[a]);
}

void setUnion(int a, int b) {
	a = findBoss(a);
	b = findBoss(b);

	if (a != b)
		boss[b] = a;
}


int main() {

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int V, E;
	cin >> V >> E;

	for (int i = 0; i < E; i++) {
		int a, b, c;
		cin >> a >> b >> c;

		vec.push_back(make_pair(c, make_pair(a, b)));
	}

	sort(vec.begin(), vec.end());

	for (int i = 1; i <= V; i++) {
		boss[i] = i;
	}

	int result = 0;
	for (int i = 0; i < E; i++) {
		int a = vec[i].second.first;
		int b = vec[i].second.second;
		if (findBoss(a) != findBoss(b)) {
			setUnion(a, b);
			result += vec[i].first;
		}
	}

	cout << result;

	return 0;
}

'APS > 백준' 카테고리의 다른 글

[2252] 줄 세우기 C++  (0) 2022.04.18
[5052] 전화번호 목록  (0) 2022.03.15
[21924] 도시 건설 C++  (0) 2022.03.05
[14716] 현수막 C++  (0) 2022.03.05
[10816] 숫자 카드2 C++  (0) 2022.03.03

https://www.acmicpc.net/problem/5052

 

5052번: 전화번호 목록

첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가

www.acmicpc.net

// https://www.acmicpc.net/problem/5052

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

using namespace std;

int main() {
	int t, n;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n;
		string input[10000];
		for (int j = 0; j < n; j++) {
			cin >> input[j];
		}
		
		sort(input, input + n);

		int flag = 0;
		for (int i = 0; i < n-1; i++) {
			string tmp1 = input[i];
			string tmp2 = input[i + 1];

			if (tmp1.size() > tmp2.size())
				continue;

			else if(tmp1 == tmp2.substr(0,tmp1.size())) {
				cout << "NO" << "\n";
				flag = 1;
				break;
			}
		}

		if(flag==0)
			cout << "YES" << "\n";
	}

	return 0;
}

'APS > 백준' 카테고리의 다른 글

[2252] 줄 세우기 C++  (0) 2022.04.18
[1197] 최소 스패닝 트리 C++  (0) 2022.03.15
[21924] 도시 건설 C++  (0) 2022.03.05
[14716] 현수막 C++  (0) 2022.03.05
[10816] 숫자 카드2 C++  (0) 2022.03.03

https://www.acmicpc.net/problem/21924

 

21924번: 도시 건설

첫 번째 줄에 건물의 개수 $N$ $(3 \le N \le 10^5 )$와 도로의 개수 $M$ $(2 \le M \le min( {N(N-1) \over 2}, 5×10^5)) $가 주어진다. 두 번째 줄 부터 $M + 1$줄까지 건물의 번호 $a$, $b$ $(1 \le a, b \le N, a ≠ b)$와 두

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

vector<pair<int, pair<int, int>>> vec;
int boss[100001];
int visit[100001] = { 0 };

int findBoss(int a) {
	if (boss[a] == a)
		return a;
	else
		return boss[a] = findBoss(boss[a]);
}

void setUnion(int a, int b) {
	a = findBoss(a);
	b = findBoss(b);

	if (a != b)
		boss[b] = a;
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N, M;
	cin >> N >> M;

	long long sum = 0;
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		sum += c;

		vec.push_back(make_pair(c, make_pair(a, b)));
	}

	sort(vec.begin(), vec.end());

	for (int i = 1; i <= N; i++) {
		boss[i] = i;
	}

	long long result = 0;
	for (int i = 0; i < M; i++) {
		int a = vec[i].second.first;
		int b = vec[i].second.second;
		if (findBoss(a) != findBoss(b)) {
			setUnion(a, b);
			visit[a] = 1;
			visit[b] = 1;
			result += vec[i].first;
		}
	}

	for (int i = 1; i < N; i++) {
		if (findBoss(i) != findBoss(i+1)) {
			cout << -1;
			return 0;
		}
	}

	cout << sum - result;

	return 0;
}

'APS > 백준' 카테고리의 다른 글

[1197] 최소 스패닝 트리 C++  (0) 2022.03.15
[5052] 전화번호 목록  (0) 2022.03.15
[14716] 현수막 C++  (0) 2022.03.05
[10816] 숫자 카드2 C++  (0) 2022.03.03
[3745] 오름세 C++  (0) 2022.03.02

https://www.acmicpc.net/problem/14716

 

14716번: 현수막

혁진이의 생각대로 프로그램을 구현했을 때, 현수막에서 글자의 개수가 몇 개인지 출력하여라.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int M, N;
int cnt = 0;
int map[251][251] = { 0 };
int visit[251][251] = { 0 };

void dfs(int y, int x) {
	int direct[8][2] = {
		-1,-1,
		-1,0,
		-1,1,
		0,-1,
		0,1,
		1,-1,
		1,0,
		1,1
	};

	for (int i = 0; i < 8; i++) {
		int dy = y + direct[i][0];
		int dx = x + direct[i][1];

		if (dy < 0 || dx < 0 || dy >= M || dx >= N)
			continue;

		if (visit[dy][dx] == 1)
			continue;

		if (map[dy][dx] == 1) {
			visit[dy][dx] = 1;
			dfs(dy, dx);
		}
	}
}

int main() {

	ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);

	cin >> M >> N;

	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			cin >> map[i][j];
		}
	}

	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			if (map[i][j] == 1 && visit[i][j] != 1) {
				dfs(i, j);
				visit[i][j] = 1;
				cnt++;
			}
		}
	}

	cout << cnt;

	return 0;
}

'APS > 백준' 카테고리의 다른 글

[5052] 전화번호 목록  (0) 2022.03.15
[21924] 도시 건설 C++  (0) 2022.03.05
[10816] 숫자 카드2 C++  (0) 2022.03.03
[3745] 오름세 C++  (0) 2022.03.02
[17245] 서버실 C++  (0) 2022.02.21

+ Recent posts