diff --git "a/10844_\354\211\254\354\232\264\352\263\204\353\213\250\354\210\230/stairs.cpp" "b/10844_\354\211\254\354\232\264\352\263\204\353\213\250\354\210\230/stairs.cpp" index 8347c7c..a5d00cd 100644 --- "a/10844_\354\211\254\354\232\264\352\263\204\353\213\250\354\210\230/stairs.cpp" +++ "b/10844_\354\211\254\354\232\264\352\263\204\353\213\250\354\210\230/stairs.cpp" @@ -3,35 +3,41 @@ 2018 Jan 17, made by Jeon */ + #include + int main(void) { - long long gds[101][10] = { 0 }; - long long res = 0; - int N; - scanf("%d", &N); - for (int i = 1; i <= 9; i++) - gds[1][i] = 1; - for (int i = 2; i <= N; i++) - { - gds[i][0] = gds[i - 1][1]; - gds[i][1] = gds[i - 1][2] + gds[i - 1][0]; - gds[i][2] = gds[i - 1][3] + gds[i - 1][1]; - gds[i][3] = gds[i - 1][4] + gds[i - 1][2]; - gds[i][4] = gds[i - 1][5] + gds[i - 1][3]; - gds[i][5] = gds[i - 1][6] + gds[i - 1][4]; - gds[i][6] = gds[i - 1][7] + gds[i - 1][5]; - gds[i][7] = gds[i - 1][8] + gds[i - 1][6]; - gds[i][8] = gds[i - 1][9] + gds[i - 1][7]; - gds[i][9] = gds[i - 1][8]; - for (int j = 0; j <= 9; j++) - gds[i][j] %= 1000000000; - } + long long gds[101][10] = { 0 }; + long long res = 0; + int N; + scanf("%d", &N); + + for (int i = 1; i <= 9; i++) + gds[1][i] = 1; + + for (int i = 2; i <= N; i++) + { + gds[i][0] = gds[i - 1][1]; + gds[i][1] = gds[i - 1][2] + gds[i - 1][0]; + gds[i][2] = gds[i - 1][3] + gds[i - 1][1]; + gds[i][3] = gds[i - 1][4] + gds[i - 1][2]; + gds[i][4] = gds[i - 1][5] + gds[i - 1][3]; + gds[i][5] = gds[i - 1][6] + gds[i - 1][4]; + gds[i][6] = gds[i - 1][7] + gds[i - 1][5]; + gds[i][7] = gds[i - 1][8] + gds[i - 1][6]; + gds[i][8] = gds[i - 1][9] + gds[i - 1][7]; + gds[i][9] = gds[i - 1][8]; + + for (int j = 0; j <= 9; j++) + gds[i][j] %= 1000000000; + } + for (int i = 0; i <= 9; i++) { - res += gds[N][i]; - res %= 1000000000; + res += gds[N][i]; + res %= 1000000000; } - printf("%lld\n", res); - return 0; -} \ No newline at end of file + printf("%lld\n", res); + return 0; +} diff --git a/JEON's solutions/10039.cpp b/JEON's solutions/10039.cpp new file mode 100644 index 0000000..91147a6 --- /dev/null +++ b/JEON's solutions/10039.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main(void) +{ + int score, sum = 0; + for(int i = 0 ; i < 5 ; i++) + { + cin >> score; + if(score < 40) + score = 40; + sum += score; + } + + cout << sum/5 << endl; +} diff --git a/JEON's solutions/10707.cpp b/JEON's solutions/10707.cpp new file mode 100644 index 0000000..0d54faf --- /dev/null +++ b/JEON's solutions/10707.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +int main(void) +{ + int a, b, c, d, p; + cin >> a >> b >> c >> d >> p; + + int x,y; + x = a * p; + + if(p <= c) + y = b; + else + y = b + (p-c)*d; + + cout << min(x,y) << endl; + return 0; +} diff --git a/JEON's solutions/10787.cpp b/JEON's solutions/10787.cpp new file mode 100644 index 0000000..4a884bc --- /dev/null +++ b/JEON's solutions/10787.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main(void) +{ + int num; + int res = 0; + cin >> num; + + for(int i = 0 ; i < 5 ; i++) + { + int car; + cin >> car; + if(num == car) + res++; + } + + cout << res << endl; + return 0; +} diff --git a/JEON's solutions/10798.cpp b/JEON's solutions/10798.cpp new file mode 100644 index 0000000..b37632d --- /dev/null +++ b/JEON's solutions/10798.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main(void) +{ + char input[5][16] = {0}; + + for(int i = 0 ; i < 5 ; i++) + cin >> input[i]; + + for(int i = 0 ; i < 16 ; i++) + for(int j = 0 ; j < 5 ; j++) + { + if(input[j][i] == 0) + continue; + else + cout << input[j][i]; + } + cout << endl; + return 0; +} diff --git a/JEON's solutions/10813.cpp b/JEON's solutions/10813.cpp new file mode 100644 index 0000000..2b6cfad --- /dev/null +++ b/JEON's solutions/10813.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int main(void) +{ + int N, M, i, j; + cin >> N >> M; + + int* basket = new int [N+1]; + + for(int i = 1 ; i <= N ; i++) + basket[i] = i; + + while(M--) + { + cin >> i >> j; + swap(basket[i], basket[j]); + } + + for(int i = 1 ; i <= N ; i++) + cout << basket[i] << " "; + cout< +#include +#include +#include +#include + +using namespace std; + +int main(void) +{ + char command[12] = ""; + vector v; + + int N; + cin >> N; + getchar(); + + while(N--) + { + cin.getline(command, 12, '\n'); + if(!strcmp(command, "pop")) + { + if(v.size() == 0) + cout << -1 << endl; + else + { + cout << v.back() << endl; + v.pop_back(); + } + } + else if(!strcmp(command, "size")) + { + cout << v.size() << endl; + } + else if(!strcmp(command, "empty")) + { + if(v.size() == 0) + cout << 1 << endl; + else + cout << 0 << endl; + } + else if(!strcmp(command, "top")) + { + if(v.size() == 0) + cout << -1 << endl; + else + cout << v.back() << endl; + } + else + { + char* token = strtok(command, " "); + token = strtok(NULL, " "); + v.push_back(atoi(token)); + } + } + return 0; +} diff --git a/JEON's solutions/10845.cpp b/JEON's solutions/10845.cpp new file mode 100644 index 0000000..9f16782 --- /dev/null +++ b/JEON's solutions/10845.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int main(void) +{ + char command[12] = ""; + vector v; + + int N; + cin >> N; + getchar(); + + while(N--) + { + cin.getline(command, 12, '\n'); + if(!strcmp(command, "pop")) + { + if(v.size() == 0) + cout << -1 << endl; + else + { + cout << v.front() << endl; + v.erase(v.begin()); + } + } + else if(!strcmp(command, "size")) + { + cout << v.size() << endl; + } + else if(!strcmp(command, "empty")) + { + if(v.size() == 0) + cout << 1 << endl; + else + cout << 0 << endl; + } + else if(!strcmp(command, "front")) + { + if(v.size() == 0) + cout << -1 << endl; + else + cout << v.front() << endl; + } + else if(!strcmp(command, "back")) + { + if(v.size() == 0) + cout << -1 << endl; + else + cout << v.back() << endl; + } + else + { + char* token = strtok(command, " "); + token = strtok(NULL, " "); + v.push_back(atoi(token)); + } + } + return 0; +} diff --git a/JEON's solutions/10871.cpp b/JEON's solutions/10871.cpp new file mode 100644 index 0000000..3fef4fc --- /dev/null +++ b/JEON's solutions/10871.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +int main(void) +{ + int N, X; + cin >> N >> X; + while(N--) + { + int num; + cin >> num; + if(X > num) + cout << num << " "; + } + cout << endl; + return 0; +} diff --git a/JEON's solutions/10872.cpp b/JEON's solutions/10872.cpp new file mode 100644 index 0000000..e5f4a4e --- /dev/null +++ b/JEON's solutions/10872.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main(void) +{ + int fac[13] = {0}; + int N; + cin >> N; + + fac[0] = 1; + for(int i = 1 ; i <= N ; i++) + { + fac[i] = fac[i-1] * i; + } + + cout << fac[N] << endl; + return 0; +} diff --git a/JEON's solutions/10886.cpp b/JEON's solutions/10886.cpp new file mode 100644 index 0000000..b919572 --- /dev/null +++ b/JEON's solutions/10886.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main(void) +{ + int N, num, zero = 0, one = 0; + cin >> N; + while(N--) + { + cin >> num; + if(num) + one++; + else + zero++; + } + + if(one > zero) + cout << "Junhee is cute!" << endl; + else + cout <<"Junhee is not cute!" << endl; + + return 0; +} diff --git a/JEON's solutions/10984.cpp b/JEON's solutions/10984.cpp new file mode 100644 index 0000000..99c18d3 --- /dev/null +++ b/JEON's solutions/10984.cpp @@ -0,0 +1,25 @@ +#include +#include +using namespace std; + +int main(void) +{ + int T, N, C; + double G; + cin >> T; + while(T--) + { + cin >> N; + int sum_C = 0; + double sum_G = 0; + + for(int i = 0 ; i < N ; i++) + { + cin >> C >> G; + sum_C += C; + sum_G += (C*G); + } + printf("%d %.1f\n", sum_C, sum_G/sum_C); + } + return 0; +} diff --git a/JEON's solutions/11047.cpp b/JEON's solutions/11047.cpp new file mode 100644 index 0000000..6f01185 --- /dev/null +++ b/JEON's solutions/11047.cpp @@ -0,0 +1,30 @@ +#include +#include + +using namespace std; + +int main(void) +{ + int N, K; + cin >> N >> K; + vector v; + + while(N--) + { + int coin; + cin >> coin; + v.push_back(coin); + } + + int cnt = 0; + + for(int i = v.size() - 1 ; i >= 0 && K != 0; i--) + { + int m = K / v[i]; + cnt += m; + K -= (v[i] * m); + } + + cout << cnt << endl; + return 0; +} diff --git a/JEON's solutions/11399.cpp b/JEON's solutions/11399.cpp new file mode 100644 index 0000000..269b9b7 --- /dev/null +++ b/JEON's solutions/11399.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +int main(void) +{ + int N, sum = 0; + cin >> N; + + vector v; + while(N--) + { + int pi; + cin >> pi; + v.push_back(pi); + } + + sort(v.begin(), v.end()); + + int len = v.size(); + int temp = 0; + for(int i = 0 ; i < len ; i++) + { + temp += v[i]; + sum += temp; + } + + cout << sum << endl; + return 0; +} diff --git a/JEON's solutions/1152.cpp b/JEON's solutions/1152.cpp new file mode 100644 index 0000000..bcb1c2a --- /dev/null +++ b/JEON's solutions/1152.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +using namespace std; + +int main(void) +{ + char str[1000000]; + int count = 0; + + cin.getline(str, 1000000); + + char *token = strtok(str, " "); + while(token != NULL) + { + count++; + token = strtok(NULL, " "); + } + cout< +#include +#include + +using namespace std; + +int main(void) +{ + char result[30] = {0}; + char name[151][31] = {0}; + int N; + cin >> N; + + for(int i = 1 ; i <= N ; i++) + { + cin >> name[i]; + } + + for(int i = 'a' ; i<='z' ; i++) + { + int cnt = 0; + for(int j = 1 ; j <= N ; j++) + { + if(name[j][0] == i) + cnt++; + } + if(cnt >= 5) + sprintf(result, "%s%c", result, i); + } + + if(strlen(result) == 0) + cout << "PREDAJA" << endl; + else + cout << result << endl; + return 0; +} diff --git a/JEON's solutions/12790.cpp b/JEON's solutions/12790.cpp new file mode 100644 index 0000000..01d410d --- /dev/null +++ b/JEON's solutions/12790.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int main(void) +{ + int T; + cin >> T; + while(T--) + { + int charc[4] = { 0 }; + for(int i = 0 ; i < 8 ; i++) + { + int input; + cin >> input; + charc[i%4] += input; + } + + if(charc[0] < 1) + charc[0] = 1; + + if(charc[1] < 1) + charc[1] = 1; + + if(charc[2] < 0) + charc[2] = 0; + + cout << 1*charc[0] + 5*charc[1] + 2*(charc[2] + charc[3]) << endl; + } + + return 0; +} diff --git a/JEON's solutions/12791.cpp b/JEON's solutions/12791.cpp new file mode 100644 index 0000000..68fa13e --- /dev/null +++ b/JEON's solutions/12791.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +using namespace std; + +struct album{ + int year; + char album_name[60]; +}; +void init(album *star); + +int main(void) +{ + album star[25]; + init(star); + int T; + cin >> T; + while(T--) + { + char result[1000] = {0}; + int cnt = 0; + int s, e; + + cin >> s >> e; + + for(int i = 0 ; i < 25 ; i++) + { + if(star[i].year >= s && star[i].year <= e) + { + cnt++; + sprintf(result, "%s\n%d %s",result, star[i].year, star[i].album_name); + } + } + + cout << cnt << result << endl; + } + return 0; +} + +void init(album *star) +{ + star[0].year = 1967; strcpy(star[0].album_name, "DavidBowie"); + star[1].year = 1969; strcpy(star[1].album_name, "SpaceOddity"); + star[2].year = 1970; strcpy(star[2].album_name, "TheManWhoSoldTheWorld"); + star[3].year = 1971; strcpy(star[3].album_name, "HunkyDory"); + star[4].year = 1972; strcpy(star[4].album_name, "TheRiseAndFallOfZiggyStardustAndTheSpidersFromMars"); + star[5].year = 1973; strcpy(star[5].album_name, "AladdinSane"); + star[6].year = 1973; strcpy(star[6].album_name, "PinUps"); + star[7].year = 1974; strcpy(star[7].album_name, "DiamondDogs"); + star[8].year = 1975; strcpy(star[8].album_name, "YoungAmericans"); + star[9].year = 1976; strcpy(star[9].album_name, "StationToStation"); + star[10].year = 1977; strcpy(star[10].album_name, "Low"); + star[11].year = 1977; strcpy(star[11].album_name, "Heroes"); + star[12].year = 1979; strcpy(star[12].album_name, "Lodger"); + star[13].year = 1980; strcpy(star[13].album_name, "ScaryMonstersAndSuperCreeps"); + star[14].year = 1983; strcpy(star[14].album_name, "LetsDance"); + star[15].year = 1984; strcpy(star[15].album_name, "Tonight"); + star[16].year = 1987; strcpy(star[16].album_name, "NeverLetMeDown"); + star[17].year = 1993; strcpy(star[17].album_name, "BlackTieWhiteNoise"); + star[18].year = 1995; strcpy(star[18].album_name, "1.Outside"); + star[19].year = 1997; strcpy(star[19].album_name, "Earthling"); + star[20].year = 1999; strcpy(star[20].album_name, "Hours"); + star[21].year = 2002; strcpy(star[21].album_name, "Heathen"); + star[22].year = 2003; strcpy(star[22].album_name, "Reality"); + star[23].year = 2013; strcpy(star[23].album_name, "TheNextDay"); + star[24].year = 2016; strcpy(star[24].album_name, "BlackStar"); + +} diff --git a/JEON's solutions/13163.cpp b/JEON's solutions/13163.cpp new file mode 100644 index 0000000..46a749c --- /dev/null +++ b/JEON's solutions/13163.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +int main(void) +{ + int N; + char name[101]; + + cin >> N; + getchar(); + + while(N--) + { + cin.getline(name, 101); + + char* token = NULL; + token = strtok(name, " "); + char god_name[101] = "god"; + + while(token != NULL) + { + token = strtok(NULL, " "); + if(token != NULL) + strcat(god_name, token); + } + + cout << god_name << endl; + } + + return 0; +} diff --git a/JEON's solutions/1520.cpp b/JEON's solutions/1520.cpp new file mode 100644 index 0000000..208db12 --- /dev/null +++ b/JEON's solutions/1520.cpp @@ -0,0 +1,47 @@ +#include +#include +using namespace std; + +int travel(int, int, int[][502], int[][502]); + +int main(void) +{ + int M,N; + int map[502][502] = {0}; + int D[502][502] = {0}; + + scanf("%d %d", &M, &N); + + for(int i = 0 ; i <= 501 ; i++) + for(int j = 0 ; j <= 501 ; j++) + map[i][j] = 10001; + + for(int i = 1 ; i <= M ; i++) + for(int j = 1 ; j <= N ; j++) + scanf("%d", &map[i][j]); + + D[1][1] = 1; + + for(int i = 1 ; i <= M ; i++) + for(int j = 1 ; j <= N ; j++) + { + if(i == 1 && j == 1) + continue; + D[i][j] = travel(i, j, map, D); + } + + printf("%d\n", D[M][N]); + return 0; +} + +int travel(int y, int x, int map[][502], int D[][502]) +{ + if(map[y][x] > map[y-1][x]) + D[y][x] += D[y-1][x]; + if(map[y][x] > map[y][x-1]) + D[y][x] += D[y][x-1]; + if(map[y][x] > map[y+1][x]) + D[y][x] += travel(y+1, x, map, D); + if(map[y][x] > map[y][x]) + D[y][x] += travel(y, x+1, map, D); +} diff --git a/JEON's solutions/1722.cpp b/JEON's solutions/1722.cpp new file mode 100644 index 0000000..3f183a8 --- /dev/null +++ b/JEON's solutions/1722.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int main(void) +{ + int N, sm, k; + int soon[21] = {0}; + cin >> N >> sm; + + if(sm == 1) + { + cin >> k; + } + else + { + for(int i = 1 ; i <= N ; i++) + { + cin >> soon[i]; + } + } + return 0; +} diff --git a/JEON's solutions/1748.cpp b/JEON's solutions/1748.cpp new file mode 100644 index 0000000..b900f4e --- /dev/null +++ b/JEON's solutions/1748.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +int main(void) +{ + int N, result = 0; + cin >> N; + for(int i = 1 ; i <= N ; i++) + { + if(i < 10) + result += 1; + else if(i<100) + result += 2; + else if(i<1000) + result += 3; + else if(i<10000) + result += 4; + else if(i<100000) + result += 5; + else if(i<1000000) + result += 6; + else if(i<10000000) + result += 7; + else if(i<100000000) + result += 8; + else + result += 9; + } + + cout < +#include +#include +#include + +using namespace std; + +int main(void) +{ + vector DorB; + vector DandB; + int N,M; + cin >> N >> M; + int name_cnt = N+M; + + while(name_cnt--) + { + string name; + cin >> name; + DorB.push_back(name); + } + + sort(DorB.begin(), DorB.end()); + + for(int i = 1 ; i < (N+M) ; ) + { + if(DorB[i].compare(DorB[i-1]) == 0) + { + DandB.push_back(DorB[i]); + i += 2; + } + else + i++; + } + + cout << DandB.size() << endl; + for(int i = 0 ; i < DandB.size() ; i++) + cout << DandB[i] << endl; + return 0; +} diff --git a/JEON's solutions/1789.cpp b/JEON's solutions/1789.cpp new file mode 100644 index 0000000..0a64987 --- /dev/null +++ b/JEON's solutions/1789.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main(void) +{ + long long S; + long long i; + long long result = 0; + cin >> S; + + for(i = 0 ; S != 0 ; i++) + { + if(S-i == 0) + break; + if(S-i >= i+1) + { + S -= i; + result++; + } + } + cout << result << endl; + return 0; +} diff --git a/JEON's solutions/2193.cpp b/JEON's solutions/2193.cpp new file mode 100644 index 0000000..62a1a93 --- /dev/null +++ b/JEON's solutions/2193.cpp @@ -0,0 +1,17 @@ + +#include + +int main(void) +{ + int N; + long long D[91] = {0}; + + scanf("%d", &N); + D[1] = 1; + + for(int i = 2 ; i <= N ; i++) + D[i] += D[i-1] + D[i-2]; + + printf("%lld\n", D[N]); + return 0; +} diff --git a/JEON's solutions/2200.cpp b/JEON's solutions/2200.cpp new file mode 100644 index 0000000..6dff422 --- /dev/null +++ b/JEON's solutions/2200.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +using namespace std; +int main(void) +{ + unsigned long long count; + string gs; + vector v; + int N; + cin >> N; + for(int i = 0 ; i <= N ; i++) + { + int num; + cin >> num; + v.push_back(num); + } + + count = 1; + + if(N != 1) + { + for(int i = 1 ; i < N ; i++) + { + if(v[i] == 0) + count+=2; + else + { + stringstream s; + count += 3; + s << v[i]; + gs = s.str(); + count += gs.length(); + } + } + } + + if(v[N] != 0) + { + stringstream s; + s << v[N]; + gs = s.str(); + count += 2; + count += gs.length(); + } + else + count++; + + cout << count << endl; + return 0; +} diff --git a/JEON's solutions/2468.cpp b/JEON's solutions/2468.cpp new file mode 100644 index 0000000..5c7ee45 --- /dev/null +++ b/JEON's solutions/2468.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +using namespace std; + +const int y_dir[4] = {-1, 0 , 1, 0}; +const int x_dir[4] = {0, 1, 0, -1}; + +int Jangma(int,int[][101]); +int Bfs(int, int[][101], int[][101]); +int main(void) +{ + int N; + int map[101][101] = {0}; + scanf("%d",&N); + + for(int i = 1 ; i <= N; i++) + for(int j = 1; j <= N ; j++) + scanf("%d", &map[i][j]); + + printf("%d", Jangma(N, map)); + return 0; +} + +int Jangma(int N, int map[][101]) +{ + struct pos{ + int y; + int x; + }; + int max_area = -1; + int visited[101][101] = {0}; + //비의 양 : 2 ~ N-1 + + for(int rain = 2 ; rain < N ; rain++) + { + int visited[101][101] = {0}; + for(int i = 1; i <= N ; i++) + { + for(int j = 1 ; j<= N ; j++) + { + + } + } + } + + return max_area; +} + +int Bfs(int N, int map[][101], int visited[][101]) +{ + +} diff --git a/JEON's solutions/2490.cpp b/JEON's solutions/2490.cpp new file mode 100644 index 0000000..82b2f1d --- /dev/null +++ b/JEON's solutions/2490.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main(void) +{ + for(int i = 0 ; i < 3 ; i++) + { + int yut, b = 0, d = 0; + for(int j = 0 ; j < 4 ; j++) + { + cin >> yut; + if(yut == 0) + b++; + else + d++; + } + + if(b == 1) + cout << "A" << endl; + else if(b == 2) + cout << "B" << endl; + else if(b == 3) + cout << "C" << endl; + else if(b == 4) + cout << "D" << endl; + else + cout << "E" << endl; + } + return 0; +} diff --git a/JEON's solutions/2563.cpp b/JEON's solutions/2563.cpp new file mode 100644 index 0000000..3292ceb --- /dev/null +++ b/JEON's solutions/2563.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +int main(void) +{ + int paper[101][101] = {0}; + int sak, area = 0; + cin >> sak; + + while(sak--) + { + int x, y; + cin >> x >> y; + + for(int i = y ; i < (y+10) ; i++) + for(int j = x ; j < (x+10) ; j++) + paper[i][j] = 1; + } + + for(int i = 0 ; i < 101 ; i++) + for(int j = 0 ; j <101 ; j++) + if(paper[j][i] == 1) + area++; + + cout << area << endl; + + return 0; +} diff --git a/JEON's solutions/2577.c b/JEON's solutions/2577.c new file mode 100644 index 0000000..b6f1ba4 --- /dev/null +++ b/JEON's solutions/2577.c @@ -0,0 +1,21 @@ +#include +#include +int main(void) +{ + int a, b, c, len, i; + int res[10] = {0}; + char abc[12] = {0}; + + scanf("%d %d %d", &a, &b, &c); + sprintf(abc, "%d", a*b*c); + + len = strlen(abc); + printf("len : %d\n", len); + for(i = 0 ; i < len ; i++) + res[abc[i]]++; + + for(i = 0 ; i < 10 ; i ++) + printf("%d\n", res[i]); + + return 0; +} diff --git a/JEON's solutions/2577.cpp b/JEON's solutions/2577.cpp new file mode 100644 index 0000000..6e905f5 --- /dev/null +++ b/JEON's solutions/2577.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +using namespace std; +int main(void) +{ + int a, b, c; + cin >> a >> b >> c; + + char abc[12]; + sprintf(abc, "%d", a*b*c); + + int res[10] = {0}; + int len = strlen(abc); + for(int i = 0 ; i < len ; i++) + res[(int)(abc[i] - '0')]++; + + for(int i = 0 ; i < 10 ; i ++) + cout << res[i] << endl; + + return 0; +} diff --git a/JEON's solutions/2606.cpp b/JEON's solutions/2606.cpp new file mode 100644 index 0000000..94f7fd9 --- /dev/null +++ b/JEON's solutions/2606.cpp @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +vector v; +int C, T; +int total = 0; +int net[101][101] = {0}; +int virus[101] = {0}; + +void infection(int com) +{ + for(int i = 1 ; i <= C ; i++) + { + if(net[com][i] == 1 && virus[i] == 0) + { + virus[com] = 1; + v.push_back(i); + total++; + } + } + + if(v.size() == 0) + return; + + int temp = v.front(); + v.erase(v.begin()); + infection(temp); +} + +int main(void) +{ + cin >> C >> T; + + while(T--) + { + int i, j; + cin >> i >> j; + net[i][j] = 1; + net[j][i] = 1; + } + + virus[1] = 1; + infection(1); + + cout << total << endl; + + return 0; +} diff --git a/JEON's solutions/2744.cpp b/JEON's solutions/2744.cpp new file mode 100644 index 0000000..1af813f --- /dev/null +++ b/JEON's solutions/2744.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +using namespace std; + +int main(void) +{ + string str; + cin >> str; + + for(int i = 0 ; str[i] ; i++) + { + if(isupper(str[i])) + str[i] = tolower(str[i]); + else + str[i] = toupper(str[i]); + } + cout << str << endl; + return 0; +} diff --git a/JEON's solutions/2783.cpp b/JEON's solutions/2783.cpp new file mode 100644 index 0000000..b59c0b1 --- /dev/null +++ b/JEON's solutions/2783.cpp @@ -0,0 +1,21 @@ +#include +#include +using namespace std; + +int main(void) +{ + double mini = 100000.0; + double cvs[101][2] = {0}; + cin >> cvs[0][0] >> cvs[0][1]; + + int T; + cin >> T; + for(int i = 1 ; i <= T ; i++) + cin >> cvs[i][0] >> cvs[i][1]; + + for(int i = 0 ; i <= T ; i++) + mini = min(mini, 1000 * cvs[i][0] / cvs[i][1]); + + printf("%.2lf\n", mini); + return 0; +} diff --git a/JEON's solutions/2798.cpp b/JEON's solutions/2798.cpp new file mode 100644 index 0000000..1a86fa6 --- /dev/null +++ b/JEON's solutions/2798.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main(void) +{ + int num[100] = {0}; + int N, M; + cin >> N >> M; + + for(int i = 0 ; i < N ; i++) + { + int temp; + cin >> temp; + num[i] = temp; + } + + + return 0; +} diff --git a/JEON's solutions/2822.cpp b/JEON's solutions/2822.cpp new file mode 100644 index 0000000..e7f751b --- /dev/null +++ b/JEON's solutions/2822.cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; + +int main(void) +{ + int scores[9] = {0}; + int temp[9] = {0}; + for(int i = 1 ; i < 9 ; i++) + { + int score; + cin >> score; + scores[i] = score; + temp[i] = score; + } + + sort(temp+1, temp+9); + int sum = 0; + for(int i = 8 ; i > 3 ; i--) + sum += temp[i]; + cout << endl; + for(int i = 8 ; i > 3 ; i--) + { + for(int j = 1 ; j < 9 ; j++) + { + if(temp[i] == scores[j] && scores[j] != -1) + { + scores[j] = -1; + break; + } + } + } + + cout << sum << endl; + + for(int i = 1 ; i < 9 ; i++) + { + if(scores[i] == -1) + cout << i << " "; + } + return 0; +} diff --git a/JEON's solutions/2828.cpp b/JEON's solutions/2828.cpp new file mode 100644 index 0000000..3932024 --- /dev/null +++ b/JEON's solutions/2828.cpp @@ -0,0 +1,38 @@ +#include +#include +using namespace std; + +int main(void) +{ + int n, j, m; + int move_len = 0; + int apples[20] = {0}; + cin >> n >> m >> j; + + int posL = 1, posR = m; + + for(int i = 0 ; i < j ; i++) + cin >> apples[i]; + + for(int i = 0 ; i < j ; i++) + { + if(apples[i] < posL) + { + int len = posL - apples[i]; + move_len += len; + posL -= len; + posR -= len; + } + else if(apples[i] > posR) + { + int len = apples[i] - posR; + move_len += len; + posL += len; + posR += len; + } + } + + cout << move_len << endl; + + return 0; +} diff --git a/JEON's solutions/2839.cpp b/JEON's solutions/2839.cpp new file mode 100644 index 0000000..f341cac --- /dev/null +++ b/JEON's solutions/2839.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + +int main(void) +{ + int N; + cin >> N; + + int result = 987654321; + + + for(int i = N/5 ; i >= 0 ; i--) + { + int remain = N - 5*i; + if(remain == 0) + { + result = N/5; + break; + } + if(remain % 3 == 0) + { + result = min(result, i + remain / 3); + } + } + + if(result == 987654321) + cout << -1 << endl; + else + cout << result << endl; + + return 0; +} diff --git a/JEON's solutions/2851.cpp b/JEON's solutions/2851.cpp new file mode 100644 index 0000000..1847ea3 --- /dev/null +++ b/JEON's solutions/2851.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int main(void) +{ + int round = 10; + int sum = 0, temp = 0, score = 0; + + while(round--) + { + cin >> score; + temp += score; + if(temp == 100) + { + sum = temp; + break; + } + else if(temp > 100) + { + if(temp - 100 <= 100 - sum) + sum = temp; + + break; + } + else + sum = temp; + } + + cout << sum << endl; + return 0; +} diff --git a/JEON's solutions/2884.cpp b/JEON's solutions/2884.cpp new file mode 100644 index 0000000..57a9a8d --- /dev/null +++ b/JEON's solutions/2884.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int main(void) +{ + int h, m; + cin >> h >> m; + + if(m >= 45) + cout << h << " " << m-45 << endl; + else + { + if(h == 0) + cout << 23 << " " << m+15 << endl; + else + cout << h-1 << " " << m+15 << endl; + } + + return 0; +} diff --git a/JEON's solutions/2935.cpp b/JEON's solutions/2935.cpp new file mode 100644 index 0000000..3c61f18 --- /dev/null +++ b/JEON's solutions/2935.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +using namespace std; + +int main(void) +{ + char a[110] = {0}; + char b[110] = {0}; + char result[220] = "1"; + char oper; + + cin >> a; + getchar(); + cin >> oper; + cin >> b; + + int zero_len_a = strlen(a) - 1; + int zero_len_b = strlen(b) - 1; + + if(oper == '*') + { + int zero_len_result = zero_len_a + zero_len_b; + for(int i = 0 ; i < zero_len_result ; i++) + strcat(result, "0"); + } + else + { + if(zero_len_a == zero_len_b) + { + strcpy(result, "2"); + for(int i = 0 ; i < zero_len_a ; i++) + strcat(result, "0"); + } + else if(zero_len_a > zero_len_b) + { + int zero_len = zero_len_a - strlen(b); + for(int i = 0 ; i < zero_len ; i++) + strcat(result, "0"); + strcat(result, b); + } + else + { + int zero_len = zero_len_b - strlen(a); + for(int i = 0 ; i < zero_len ; i++) + strcat(result, "0"); + strcat(result, a); + } + } + + cout << result << endl; + return 0; +} diff --git a/JEON's solutions/2960.cpp b/JEON's solutions/2960.cpp new file mode 100644 index 0000000..ea21679 --- /dev/null +++ b/JEON's solutions/2960.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +int main(void) +{ + int N, K, stop = 0; + int era[1001] = {0}; + int del_cnt = 0; + + cin >> N >> K; + + for(int i = 2 ; i <= N ; i++) + { + if(era[i] == 0) + { + for(int j = 1 ; i*j <= N ; j++) + { + if(era[i * j] == 0) + { + era[i * j] = 1; + del_cnt++; + if(del_cnt == K) + { + cout << i*j << endl; + stop = 1; + break; + } + } + } + } + + if(stop) + break; + } + + + return 0; +} diff --git a/JEON's solutions/3023.cpp b/JEON's solutions/3023.cpp new file mode 100644 index 0000000..c4b6a23 --- /dev/null +++ b/JEON's solutions/3023.cpp @@ -0,0 +1,66 @@ +#include +#include +using namespace std; + +int main(void) +{ + int r, c , e_r, e_c; + char result[202][202] = {0}; + + cin >> r >> c; + for(int i = 1 ; i <= r; i++) + { + for(int j = 1 ; j <= c ; j++) + cin >> result[i][j]; + getchar(); + } + + //상-우 + for(int i = 1 ; i <= r ; i++) + { + int x = 1; + for(int j = c+1 ; j <= c*2 ; j++) + { + result[i][j] = result[i][j-x]; + x+=2; + } + } + + //하 - 좌 + int x = 1; + for(int i = r+1 ; i <= r*2 ; i++) + { + for(int j = 1 ; j <= c ; j++) + result[i][j] = result[i-x][j]; + x += 2; + } + + //하-우 + for(int i = r+1; i <= r*2 ; i++) + { + int x = 1; + for(int j = c+1 ; j <= c*2 ; j++) + { + result[i][j] = result[i][j-x]; + x+=2; + } + } + + + cin >> e_r >> e_c; + + for(int i = 1 ; i <= r*2 ; i++) + { + for(int j = 1 ; j <= c*2 ; j++) + { + if(i == e_r && j == e_c && result[i][j] == '#') + cout << '.'; + else if(i == e_r && j == e_c && result[i][j] == '.') + cout << '#'; + else + cout << result[i][j]; + } + cout << endl; + } + return 0; +} diff --git a/JEON's solutions/3034.cpp b/JEON's solutions/3034.cpp new file mode 100644 index 0000000..5d3a992 --- /dev/null +++ b/JEON's solutions/3034.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; + +int main(void) +{ + int N, W, H, len; + double dia; + cin >> N >> W >> H; + dia = sqrt(W*W + H*H); + while(N--) + { + cin >> len; + if(len <= W || len <= H || len <= dia) + cout << "DA" << endl; + else + cout << "NE" << endl; + } + return 0; +} diff --git a/JEON's solutions/3486.cpp b/JEON's solutions/3486.cpp new file mode 100644 index 0000000..84b8dd5 --- /dev/null +++ b/JEON's solutions/3486.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +using namespace std; + +void reverse_arr(char*, int); + +int main(void) +{ + int N; + cin >> N; + while(N--) + { + char num1[11] = {0}; + char num2[11] = {0}; + char res[11] = {0}; + + cin >> num1 >> num2; + reverse_arr(num1, strlen(num1)); + reverse_arr(num2, strlen(num2)); + sprintf(res, "%d", atoi(num1) + atoi(num2)); + reverse_arr(res, strlen(res)); + cout< + +using namespace std; + +int R(int i) +{ + int temp = i; + int x = 0; + int j = 1; + while(1) + { + if(i % j == i) + break; + j *= 10; + } + + j /= 10; + + for(int k = 1 ; j > 0 ; k*=10, j /= 10) + { + x += (temp/j*k); + temp -= ((temp/j) * j); + } + + return x; +} + +int main(void) +{ + int N; + cin >> N; + while(N--) + { + int i , j; + cin >> i >> j; + cout << R(R(i) + R(j)) << endl; + } + return 0; +} diff --git a/JEON's solutions/4153.cpp b/JEON's solutions/4153.cpp new file mode 100644 index 0000000..aadaa87 --- /dev/null +++ b/JEON's solutions/4153.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; + +int main(void) +{ + int a, b, c; + while(1) + { + cin >> a >> b >> c; + if(a==0 && b==0 && c==0) + break; + + vector v; + v.push_back(a); + v.push_back(b); + v.push_back(c); + + sort(v.begin(), v.begin()+3); + + if(v[0]*v[0] + v[1]*v[1] == v[2]*v[2]) + cout<<"right"< +#include +using namespace std; + +int main(void) +{ + int n; + cin >> n; + while(n) + { + int prime_cnt = 0; + int last = 2*n; + + for(int i = n+1 ; i <= last ; i++) + { + int sqrt_i = (int)sqrt(i); + int prime = 1; + + for(int j = 2 ; j <= sqrt_i ; j++) + { + if(i % j == 0) + { + prime = 0; + break; + } + } + + if(prime == 1) + prime_cnt++; + } + + cout << prime_cnt << endl; + + cin>>n; + } + return 0; +} diff --git a/JEON's solutions/5032.cpp b/JEON's solutions/5032.cpp new file mode 100644 index 0000000..1ac1dcf --- /dev/null +++ b/JEON's solutions/5032.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main(void) +{ + int e, f, c; + cin >> e >> f >> c; + + int ini_empty = e+f; + int result = 0; + while(ini_empty >= c) + { + int temp = ini_empty % c; + result += ini_empty / c; + ini_empty = ini_empty / c + temp; + } + + cout << result << endl; + return 0; +} diff --git a/JEON's solutions/5063.cpp b/JEON's solutions/5063.cpp new file mode 100644 index 0000000..74aa029 --- /dev/null +++ b/JEON's solutions/5063.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main(void) +{ + int N; + cin >> N; + while(N--) + { + int r, e ,c; + cin >> r >> e >> c; + + if(r == (e-c)) + cout << "does not matter" << endl; + else if ( r > (e-c)) + cout << "do not advertise" << endl; + else + cout << "advertise" << endl; + } + return 0; +} diff --git a/JEON's solutions/5532.cpp b/JEON's solutions/5532.cpp new file mode 100644 index 0000000..e72312a --- /dev/null +++ b/JEON's solutions/5532.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int main(void) +{ + int L, B, A, C, D; + cin >> L >> A >> B >> C >> D; + int do_day = 0; + + if(B % D == 0) + do_day = B / D; + else + do_day = B / D + 1; + + if(A % C == 0) + do_day = max(do_day, A/C); + else + do_day = max(do_day, A/C+1); + + cout << L-do_day << endl; + return 0; +} diff --git a/JEON's solutions/5543.cpp b/JEON's solutions/5543.cpp new file mode 100644 index 0000000..8f6d22d --- /dev/null +++ b/JEON's solutions/5543.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; +int main(void) +{ + int h = 2001, b = 2001; + + for(int i = 0 ; i < 3 ; i++) + { + int price; + cin >> price; + h = min(h, price); + } + + for(int i = 0 ; i < 2 ; i++) + { + int price; + cin >> price; + b = min(b, price); + } + + cout << h + b - 50 << endl; + return 0; +} diff --git a/JEON's solutions/5545.cpp b/JEON's solutions/5545.cpp new file mode 100644 index 0000000..1816a3d --- /dev/null +++ b/JEON's solutions/5545.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +using namespace std; + +int main(void) +{ + int n; + double a, b, douCal, maxCal; + int toping[1000] = {0}; + + cin >> n >> a >> b >> douCal; + + for(int i = 0 ; i < n ; i++) + cin >> toping[i]; + + sort(toping, toping+n); + + maxCal = douCal / a; + + double toping_cals = 0; + for(int i = n-1, x = 1 ; i >= 0 ; i--, x++) + { + toping_cals += toping[i]; + maxCal = max(maxCal, (douCal + toping_cals)/(a + b*x)); + } + printf("%d\n", (int)maxCal); + return 0; +} diff --git a/JEON's solutions/5554.cpp b/JEON's solutions/5554.cpp new file mode 100644 index 0000000..baf9425 --- /dev/null +++ b/JEON's solutions/5554.cpp @@ -0,0 +1,13 @@ +#include + +using namespace std; + +int main(void) +{ + int a, b, c, d; + cin >> a >> b >> c >> d; + int sum = a+b+c+d; + + cout << sum/60 << endl << sum%60 << endl; + return 0; +} diff --git a/JEON's solutions/5565.cpp b/JEON's solutions/5565.cpp new file mode 100644 index 0000000..76c6b26 --- /dev/null +++ b/JEON's solutions/5565.cpp @@ -0,0 +1,16 @@ +#include + +using namespace std; + +int main(void) +{ + int total, price, sum = 0; + cin >> total; + for(int i = 0 ; i < 9 ; i++) + { + cin >> price; + sum += price; + } + cout << total - sum << endl; + return 0; +} diff --git a/JEON's solutions/5567.cpp b/JEON's solutions/5567.cpp new file mode 100644 index 0000000..0e3955c --- /dev/null +++ b/JEON's solutions/5567.cpp @@ -0,0 +1,62 @@ +#include +#include +using namespace std; + +int relation[501][501] = {0}; +int check[501] = {0}; +vector v; +int n, m, result = 0; +int solution(int); + +int main(void) +{ + cin >> n >> m; + + while(m--) + { + int i, j; + cin >> i >> j; + relation[i][j] = 1; + relation[j][i] = 1; + } + + check[1] = 1; + for(int i = 1 ; i <= n ; i++) + { + if(relation[1][i] == 1 && check[i] == 0) + { + v.push_back(i); + check[i] = 1; + result++; + } + } + + if(v.size() != 0) + { + int temp = v.front(); + v.erase(v.begin()); + solution(temp); + } + + cout << result << endl; + return 0; +} + +int solution(int start) +{ + for(int i = 1 ; i <= n ; i++) + { + if(relation[start][i] == 1 && check[i] == 0) + { + result++; + check[i] = 1; + } + } + + if(v.size() == 0) + return 0; + + int temp = v.front(); + v.erase(v.begin()); + solution(temp); +} diff --git a/JEON's solutions/5576.cpp b/JEON's solutions/5576.cpp new file mode 100644 index 0000000..011a2e5 --- /dev/null +++ b/JEON's solutions/5576.cpp @@ -0,0 +1,23 @@ +#include +#include + +using namespace std; + +int main(void) +{ + int score_W, score_K; + int input[2][10] = {0}; + + for(int i = 0 ; i <= 1 ; i++) + for(int j = 0 ; j < 10 ; j++) + cin >> input[i][j]; + + sort(input[0], input[0]+10); + sort(input[1], input[1]+10); + + score_W = input[0][9] + input[0][8] + input[0][7]; + score_K = input[1][9] + input[1][8] + input[1][7]; + + cout << score_W << " " << score_K << endl; + return 0; +} diff --git a/JEON's solutions/5585.cpp b/JEON's solutions/5585.cpp new file mode 100644 index 0000000..140ce96 --- /dev/null +++ b/JEON's solutions/5585.cpp @@ -0,0 +1,36 @@ +#include + +using namespace std; + +int main(void) +{ + int price, mok; + cin >> price; + price = 1000 - price; + int result = 0; + + mok = price / 500; + result += mok; + price -= 500 * mok; + + mok = price / 100; + result += mok; + price -= 100 * mok; + + mok = price / 50; + result += mok; + price -= 50 * mok; + + mok = price / 10; + result += mok; + price -= 10 * mok; + + mok = price / 5; + result += mok; + price -= 5 * mok; + + result += price; + + cout< + +using namespace std; + +int main(void) +{ + int a, b, c, d; + int e, f, g, h; + + cin >> a >> b >> c >> d; + cin >> e >> f >> g >> h; + + cout << max(a+b+c+d, e+f+g+h) << endl; + return 0; +} diff --git a/JEON's solutions/5597.cpp b/JEON's solutions/5597.cpp new file mode 100644 index 0000000..8eb2a30 --- /dev/null +++ b/JEON's solutions/5597.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main(void) +{ + int num; + int student[31] = {0}; + for(int i = 0 ; i < 28 ; i++) + { + cin >> num; + student[num] = 1; + } + + for(int i = 1 ; i < 31 ; i++) + { + if(student[i] == 0) + cout << i << endl; + } + + return 0; +} diff --git a/JEON's solutions/5618.cpp b/JEON's solutions/5618.cpp new file mode 100644 index 0000000..5d24211 --- /dev/null +++ b/JEON's solutions/5618.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +void getCD(int, int, int); + +int main(void) +{ + int n; + int num1, num2, num3; + cin >> n; + if(n == 2) + { + cin >> num1 >> num2; + getCD(num1, num2 ,num2); + } + else + { + cin >> num1 >> num2 >> num3; + getCD(num1, num2, num3); + } + return 0; +} + +void getCD(int n1, int n2, int n3) +{ + int range = min(n1, min(n2, n3)); + + for(int i = 1 ; i <= range ; i++) + { + if(n1 % i == 0 && n2 % i == 0 && n3 % i == 0) + cout << i << endl; + } +} diff --git a/JEON's solutions/7562.cpp b/JEON's solutions/7562.cpp new file mode 100644 index 0000000..9456e9b --- /dev/null +++ b/JEON's solutions/7562.cpp @@ -0,0 +1,74 @@ +#include +#include + +using namespace std; + +const int y_dir[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; +const int x_dir[8] = {1, 2, 2, 1, -1, -2, -2, -1}; + +int Knight(int,int[],int[]); + +struct pos{ + int y; + int x; +}; + +int main(void) +{ + int T; + scanf("%d", &T); + while(T--) + { + int L; + int cur_pos[2] = {0}; + int tar_pos[2] = {0}; + + scanf("%d", &L); + scanf("%d %d", &cur_pos[0], &cur_pos[1]); + scanf("%d %d", &tar_pos[0], &tar_pos[1]); + + printf("%d\n", Knight(L, cur_pos, tar_pos)); + } + return 0; +} + +int Knight(int L, int cur_pos[], int tar_pos[]) +{ + int visited[301][301] = {0}; + int move_cnt = 0; + int ca = 0; // current area + queue q; + pos p = {cur_pos[0], cur_pos[1]}; + q.push(p); + + while(q.size()) + { + ca = q.size(); + for(int k = 0 ; k < ca ; k++) + { + pos p = q.front(); + q.pop(); + + if(p.y == tar_pos[0] && p.x == tar_pos[1]) + return move_cnt; + + for(int i = 0 ; i < 8 ; i++) + { + if(p.y + y_dir[i] >= 0 && p.y + y_dir[i] < L && + p.x + x_dir[i] >= 0 && p.x + x_dir[i] < L) + { + if(visited[p.y + y_dir[i]][p.x + x_dir[i]] == 0) + { + pos next = { p.y + y_dir[i], p.x + x_dir[i] }; + q.push(next); + visited[p.y + y_dir[i]][p.x + x_dir[i]] = 1; + } + } + } + } + + move_cnt++; + } + + return move_cnt; +} diff --git a/JEON's solutions/7569.cpp b/JEON's solutions/7569.cpp new file mode 100644 index 0000000..8762f1d --- /dev/null +++ b/JEON's solutions/7569.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +using namespace std; + +const int y_dir[4] = { 1, 0, -1, 0 }; +const int x_dir[4] = { 0, 1, 0, -1 }; + +struct pos +{ + int z; + int y; + int x; +}; + +int tomatoes(int[][101][101], int[][101][101], queue&); + +int main(void) +{ + int box[101][101][101] = { 0 }; + int visited[101][101][101] = { 0 }; + int M, N, H, anik_tomato = 0, empty = 0; + queue q; + + cin >> M >> N >> H; + + for(int z = 0 ; z < 101 ; z++) + for (int i = 0; i < 101; i++) + for (int j = 0; j < 101; j++) + visited[z][i][j] = 1; + + for(int z = 1 ; z <= H ; z++) + { + for (int i = 1; i <= N; i++) + { + for (int j = 1; j <= M; j++) + { + cin >> box[z][i][j]; + if (box[z][i][j] == 1) + { + pos p = { z, i, j }; + q.push(p); + } + else if (box[z][i][j] == 0) + { + anik_tomato += 1; + visited[z][i][j] = -1; + } + else + empty += 1; + } + } + } + + if (anik_tomato == 0 && empty != M*N*H) + printf("0\n"); + else + { + int result = tomatoes(box, visited, q); + int cannot = 0; + + for(int z = 1 ; z <= H ; z++) + { + for (int i = 1; i <= N; i++) + { + for (int j = 1; j <= M; j++) + { + if (visited[z][i][j] == -1) + { + cannot = 1; + break; + } + } + if (cannot) + break; + } + } + + if (cannot) + printf("-1\n"); + else + printf("%d\n", result); + } + + return 0; +} + +int tomatoes(int box[][101][101], int visited[][101][101], queue &q) +{ + int res = 0; + + while (q.size()) + { + int cnt = q.size(); + for (int i = 0; i < cnt; i++) + { + pos ctp = q.front(); //current_tomato_pos + q.pop(); + for (int z = 0; z < 4; z++) + { + if (box[ctp.z][ctp.y + y_dir[z]][ctp.x + x_dir[z]] == 0 && + visited[ctp.z][ctp.y + y_dir[z]][ctp.x + x_dir[z]] == -1) + { + pos ntp = { ctp.z, ctp.y + y_dir[z], ctp.x + x_dir[z] }; // next_t_p + q.push(ntp); + visited[ntp.z][ntp.y][ntp.x] = 1; + } + } + if (box[ctp.z - 1][ctp.y][ctp.x] == 0 && + visited[ctp.z - 1][ctp.y][ctp.x] == -1) + { + pos ntp = { ctp.z - 1, ctp.y, ctp.x}; // next_t_p + q.push(ntp); + visited[ntp.z][ntp.y][ntp.x] = 1; + } + if (box[ctp.z + 1][ctp.y][ctp.x] == 0 && + visited[ctp.z + 1][ctp.y][ctp.x] == -1) + { + pos ntp = { ctp.z + 1, ctp.y, ctp.x}; // next_t_p + q.push(ntp); + visited[ntp.z][ntp.y][ntp.x] = 1; + } + } + if(q.size() != 0) + res++; + } + + + return res; +} diff --git a/JEON's solutions/7576.cpp b/JEON's solutions/7576.cpp new file mode 100644 index 0000000..6adade2 --- /dev/null +++ b/JEON's solutions/7576.cpp @@ -0,0 +1,53 @@ +#include +#include +using namespace std; + +int result = 0; + +void tomato(int int); + +int main(void) +{ + int box[1002][1002] = {0}; + int m, n, total = 0; + cin >> m >> n; + + for(int i = 1 ; i <= n ; i++) + for(int j = 1 ; j <= m ; j++) + { + cin >> box[i][j]; + if(box[i][j] != -1) + total++; + } + + for(int i = 0 ; i <= n+1 ; i++) + { + box[i][0] = -99; + box[i][m+1] = -99; + } + + for(int i = 0 ; i <= m+1 ; i++) + { + box[0][i] = -99; + box[n+1][i] = -99; + } + + + + + /* + for(int i = 0 ; i <= n+1 ; i++) + { + for(int j = 0 ; j <= m+1 ; j++) + cout << box[i][j] << " "; + cout << endl; + } + */ + + return 0; +} + +void tomato(int i, int j) +{ + +} diff --git a/JEON's solutions/8320.cpp b/JEON's solutions/8320.cpp new file mode 100644 index 0000000..b49d01b --- /dev/null +++ b/JEON's solutions/8320.cpp @@ -0,0 +1,36 @@ +#include + +using namespace std; + +int cnt(int); + +int main(void) +{ + int n; + int result = 1; + cin >> n; + + for(int i = 2 ; i <= n ; i++) + result += cnt(i); + + cout << result << endl; + return 0; +} + +int cnt(int i) //약수의 개수 / 2 or /2 + 1 +{ + int result = 0; + + for(int x = 1 ; x <= i ; x++) + { + if(i % x == 0) + result++; + } + + if(result % 2 == 0) + result /= 2; + else + result = result / 2 + 1; + + return result; +} diff --git a/JEON's solutions/8911.cpp b/JEON's solutions/8911.cpp new file mode 100644 index 0000000..ee88961 --- /dev/null +++ b/JEON's solutions/8911.cpp @@ -0,0 +1,64 @@ +#include +#include + +using namespace std; +enum {N, E, S, W}; + +struct pos{ + int posX; + int posY; + int SX; // Small X + int LX; // Large X + int SY; + int LY; + + void move(int dir) + { + if(dir == N) + posY += 1; + else if(dir == E) + posX += 1; + else if(dir == S) + posY -= 1; + else // W + posX -= 1; + LX = max(LX, posX); + LY = max(LY, posY); + SX = min(SX, posX); + SY = min(SY, posY); + } + + int range(void) + { + return (LX - SX) * (LY - SY); + } +}; + +int main(void) +{ + int T; + cin >> T; + while(T--) + { + int direction = N; + pos P = {0, 0, 0, 0, 0, 0}; + + char order[501]; + cin >> order; + + int length = strlen(order); + for(int i = 0 ; i < length ; i++) + { + if(order[i] == 'R') + direction = (direction + 1) % 4; + else if(order[i] == 'L') + direction = (direction + 3) % 4; + else if(order[i] == 'F') + P.move(direction); + else // B + P.move((direction+2) % 4); + } + cout << P.range() << endl; + } + return 0; +} diff --git a/JEON's solutions/8979.cpp b/JEON's solutions/8979.cpp new file mode 100644 index 0000000..0df4e61 --- /dev/null +++ b/JEON's solutions/8979.cpp @@ -0,0 +1,20 @@ +#include +#define MAX_N 1001 +using namespace std; + +int main(void) +{ + int temp; + int gold[MAX_N] = {0}; + int silver[MAX_N] = {0}; + int bronze[MAX_N] = {0}; + int rank[MAX_N] = {0}; + int N, K; + cin >> N >> K; + + for(int i = 1 ; i <= N ; i++) + cin >> temp >> gold[i] >> silver[i] >> bronze[i]; + + + return 0; +} diff --git a/JEON's solutions/9012.cpp b/JEON's solutions/9012.cpp new file mode 100644 index 0000000..ce58f97 --- /dev/null +++ b/JEON's solutions/9012.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +using namespace std; + +void vps(vector&); + +int main(void) +{ + int T; + cin >> T; + getchar(); + + while(T--) + { + vector v; + char c = getchar(); + while(c != '\n') + { + v.push_back(c); + c = getchar(); + } + + vps(v); + } + return 0; +} + +void vps(vector &v) +{ + vector temp; + + int len = v.size(); + for(int i = 0 ; i < len ; i++) + { + char p = v.back(); + v.pop_back(); + if(p == ')') + temp.push_back(p); + else + { + if(temp.size() == 0) + { + cout << "NO" << endl; + return; + } + else + temp.pop_back(); + } + } + + if(temp.size() != 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} diff --git a/JEON's solutions/9417.cpp b/JEON's solutions/9417.cpp new file mode 100644 index 0000000..a985df9 --- /dev/null +++ b/JEON's solutions/9417.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +int main(void) +{ + int N; + cin >> N; + getchar(); + while(N--) + { + char num[11] = {0}; + vector v; + int i = 0; + while(1) + { + char c = getchar(); + if(c == ' ') + { + v.push_back(atoi(num)); + memset(num, 0, 11); + i = 0; + } + else if(c == '\n') + { + v.push_back(atoi(num)); + break; + } + else + { + num[i] = c; + i++; + } + } + + int size = v.size(); + int maxi = 0; + for(int i = 0 ; i < size ; i++) + if(v[i] > maxi) + maxi = v[i]; + + int maxGCD = 0; + int limit = maxi/2; + for(int i = 1 ; i <= limit ; i++) + { + int cnt = 0; + for(int j = 0 ; j < size ; j++) + { + if(v[j] % i == 0) + cnt++; + } + if(cnt >= 2) + maxGCD = i; + } + + cout << maxGCD << endl; + } + return 0; +} diff --git a/JEON's solutions/9498.cpp b/JEON's solutions/9498.cpp new file mode 100644 index 0000000..5841a91 --- /dev/null +++ b/JEON's solutions/9498.cpp @@ -0,0 +1,36 @@ +#include + +enum {SUN, MON, TUE, WED, THU, FRI, SAT}; +using namespace std; + +int main(void) +{ + int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int m, d , day = 0; + cin >> m >> d; + + for(int i = 1 ; i < m ; i++) + day += days[i]; + + day += d; + + int yoil = day % 7; + + if(yoil == SUN) + cout << "SUN" << endl; + else if(yoil == MON) + cout << "MON" << endl; + else if(yoil == TUE) + cout << "TUE" << endl; + else if(yoil == WED) + cout << "WED" << endl; + else if(yoil == THU) + cout << "THU" << endl; + else if(yoil == FRI) + cout << "FRI" << endl; + else + cout << "SAT" << endl; + + + return 0; +} diff --git a/JEON's solutions/coin2.cpp b/JEON's solutions/coin2.cpp new file mode 100644 index 0000000..d50ca1e --- /dev/null +++ b/JEON's solutions/coin2.cpp @@ -0,0 +1,32 @@ +#include +#define MAX_N 101 +#define MAX_K 10001 +#define MIN(A,B) A>B?B:A +int main(void) +{ + + int D[MAX_K] = { 0 }; + int coin[MAX_N] = { 0 }; + int n ,k; + int result = -1; + scanf("%d %d", &n, &k); + + for(int i = 1 ; i <= n ; i++) + scanf("%d", &coin[i]); + + for(int i = 1 ; i <= k ; i++) + D[i] = 987654321; + + for(int i = 1 ; i <= n ; i++) + for(int j = 1 ; j <= k ; j++) + if( j >= coin[i]) + D[j] = MIN(D[j], D[j-coin[i]] + 1); + + + if(D[k] != 987654321) + result = D[k]; + + printf("%d\n", result); + + return 0; +}