๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)315

[๋ฐฑ์ค€,c++] 1371๋ฒˆ - ๊ฐ€์žฅ ๋งŽ์€ ๊ธ€์ž 1371๋ฒˆ: ๊ฐ€์žฅ ๋งŽ์€ ๊ธ€์ž ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ ๊ธ€์˜ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง„๋‹ค. ๊ธ€์€ ์ตœ๋Œ€ 50๊ฐœ์˜ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ฐ ์ค„์€ ์ตœ๋Œ€ 50๊ฐœ์˜ ๊ธ€์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์—๋Š” ๊ณต๋ฐฑ๊ณผ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋งŒ ์žˆ๋‹ค. ๋ฌธ์žฅ์— ์•ŒํŒŒ๋ฒณ์€ ์ ์–ด๋„ ํ•˜๋‚˜ ์ด www.acmicpc.net #include #include using namespace std; char alphabet[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' }; int check[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; whil.. 2021. 11. 5.
[๋ฐฑ์ค€,c++] 11497๋ฒˆ - ํ†ต๋‚˜๋ฌด ๊ฑด๋„ˆ๋›ฐ๊ธฐ 11497๋ฒˆ: ํ†ต๋‚˜๋ฌด ๊ฑด๋„ˆ๋›ฐ๊ธฐ ๋‚จ๊ทœ๋Š” ํ†ต๋‚˜๋ฌด๋ฅผ ์„ธ์›Œ ๋†“๊ณ  ๊ฑด๋„ˆ๋›ฐ๊ธฐ๋ฅผ ์ข‹์•„ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ N๊ฐœ์˜ ํ†ต๋‚˜๋ฌด๋ฅผ ์›ํ˜•์œผ๋กœ ์„ธ์›Œ ๋†“๊ณ  ๋›ฐ์–ด๋†€๋ ค๊ณ  ํ•œ๋‹ค. ๋‚จ๊ทœ๋Š” ์›ํ˜•์œผ๋กœ ์ธ์ ‘ํ•œ ์˜† ํ†ต๋‚˜๋ฌด๋กœ ๊ฑด๋„ˆ๋›ฐ๋Š”๋ฐ, ์ด๋•Œ ๊ฐ ์ธ์ ‘ํ•œ ํ†ต๋‚˜๋ฌด์˜ ๋†’์ด www.acmicpc.net ์ •๊ทœ๋ถ„ํฌํ‘œ์ฒ˜๋Ÿผ ๋ฐฐ์—ด ๊ฐ€์šด๋ฐ ์ œ์ผ ํฐ ๊ฐ’์„ ๋„ฃ๊ณ  ์–‘์ชฝ์— ์ ์  ์ž‘์•„์ง€๋Š” ์ˆ˜๋กœ ๋‚˜์—ด์‹œํ‚จ๋‹ค. ๊ทธ ํ›„ ์„ ํ˜•ํƒ์ƒ‰์„ ํ•ด์„œ ์ฐจ์ด๋ฅผ ๊ตฌํ•ด ์ฐจ์ด๊ฐ€ ์ ค ํฐ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค. #include #include #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int T; cin>>T; while(T--){ int n,ans=0; cin>>n; vectorv; for.. 2021. 11. 5.
[๋ฐฑ์ค€,c++] 1357๋ฒˆ - ๋’ค์ง‘ํžŒ ๋ง์…ˆ 1357๋ฒˆ: ๋’ค์ง‘ํžŒ ๋ง์…ˆ ์–ด๋–ค ์ˆ˜ X๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, X์˜ ๋ชจ๋“  ์ž๋ฆฌ์ˆ˜๊ฐ€ ์—ญ์ˆœ์ด ๋œ ์ˆ˜๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. Rev(X)๋ฅผ X์˜ ๋ชจ๋“  ์ž๋ฆฌ์ˆ˜๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋งŒ๋“œ๋Š” ํ•จ์ˆ˜๋ผ๊ณ  ํ•˜์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, X=123์ผ ๋•Œ, Rev(X) = 321์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ , X=100์ผ ๋•Œ, Rev( www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string x, y, temp; cin >> x >> y; reverse(x.begin(), x.end()); reverse(y.begin(), y.end()); temp = to_string(stoi(x) + stoi(y)); revers.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 1356๋ฒˆ - ์œ ์ง„ ์ˆ˜ 1356๋ฒˆ: ์œ ์ง„์ˆ˜ ์ฒซ์งธ ์ค„์— ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ์ˆ˜๋Š” 2,147,483,647๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net #include #include using namespace std; bool check; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string N; cin >> N; int tempLeft = 1; for (int i = 0; i < N.length()-1; i++) { int tempRight = 1; tempLeft *= (N[i]-'0'); for (int k = i + 1; k < N.length(); k++) { tempRight *= (N[k] - '0'); } if (tempLeft ==.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13549๋ฒˆ - ์ˆจ๋ฐ”๊ผญ์งˆ3 13549๋ฒˆ: ์ˆจ๋ฐ”๊ผญ์งˆ 3 ์ˆ˜๋นˆ์ด๋Š” ๋™์ƒ๊ณผ ์ˆจ๋ฐ”๊ผญ์งˆ์„ ํ•˜๊ณ  ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ํ˜„์žฌ ์  N(0 ≤ N ≤ 100,000)์— ์žˆ๊ณ , ๋™์ƒ์€ ์  K(0 ≤ K ≤ 100,000)์— ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ๊ฑท๊ฑฐ๋‚˜ ์ˆœ๊ฐ„์ด๋™์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜๊ฐ€ X์ผ www.acmicpc.net #include #include #define MAX 100001 using namespace std; int N,K; //N=์ˆ˜๋นˆ์ด๊ฐ€ ์žˆ๋Š” ์œ„์น˜, K=๋™์ƒ์ด ์žˆ๋Š” ์œ„์น˜ int visited[MAX]; int ans=MAX; void bfs(int start,int time){ priority_queuepq; //{์‹œ๊ฐ„,ํ˜„์žฌ ๊ฑฐ๋ฆฌ} pq.push({0,start}); visited[start]=1; while(!pq.empty().. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13420๋ฒˆ - ์‚ฌ์น™์—ฐ์‚ฐ 13420๋ฒˆ: ์‚ฌ์น™์—ฐ์‚ฐ ์‚ฌ์น™์—ฐ์‚ฐ์€ ๋ง์…ˆ, ๋บ„์…ˆ, ๊ณฑ์…ˆ, ๋‚˜๋ˆ—์…ˆ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ด๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ธฐํ˜ธ๋Š” +, -, *, / ์™€ ๊ฐ™๋‹ค. ์•„๋ž˜๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ์—์„œ ํ‘œํ˜„ํ•œ ์‚ฌ์น™ ์—ฐ์‚ฐ์˜ ์˜ˆ์ œ์ด๋‹ค. 3 * 2 = 6 ๋ฌธ www.acmicpc.net #define _CRT_SECURE_NO_WARNINGS #include int main() { long long int T; scanf("%lld", &T); for (int i = 0; i < T; i++) { long long int num1, num2, result; char cacul, equal; scanf("%lld %c %lld %c %lld", &num1, &cacul, &num2, &equal, &result); if (cacu.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13414๋ฒˆ - ์ˆ˜๊ฐ•์‹ ์ฒญ ๋ฌธ์ œ 13414๋ฒˆ: ์ˆ˜๊ฐ•์‹ ์ฒญ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋Š” ํ‘œ์ค€ ์ž…๋ ฅ์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ž…๋ ฅ์€ 1๊ฐœ์˜ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. ์ž…๋ ฅ์˜ ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ๊ณผ๋ชฉ์˜ ์ˆ˜๊ฐ• ๊ฐ€๋Šฅ ์ธ์› K(1 ≤ K ≤ 100,000)์™€ ํ•™์ƒ๋“ค์ด ๋ฒ„ํŠผ์„ ํด๋ฆญํ•œ ์ˆœ์„œ๋ฅผ ๊ธฐ๋กํ•œ ๋Œ€๊ธฐ๋ชฉ www.acmicpc.net ์ฝ”๋“œ #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); //์‹œ๊ฐ„ ์ดˆ๊ณผ ์ฝ”๋“œ /* int k, L; cin >> k >> L; vectorans; for (int i = 0; i > sno; if (find(ans.begin(), ans.end().. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 1330๋ฒˆ - ๋‘ ์ˆ˜ ๋น„๊ตํ•˜๊ธฐ 1330๋ฒˆ: ๋‘ ์ˆ˜ ๋น„๊ตํ•˜๊ธฐ ๋‘ ์ •์ˆ˜ A์™€ B๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, A์™€ B๋ฅผ ๋น„๊ตํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net #include using namespace std; string compare(int n1, int n2) { if (n1 > n2) return ">"; else if (n1 < n2) return " 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13241๋ฒˆ - ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ 13241๋ฒˆ: ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ์ •์ˆ˜ B์— 0๋ณด๋‹ค ํฐ ์ •์ˆ˜์ธ N์„ ๊ณฑํ•ด ์ •์ˆ˜ A๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๋ฉด, A๋Š” B์˜ ๋ฐฐ์ˆ˜์ด๋‹ค. ์˜ˆ: 10์€ 5์˜ ๋ฐฐ์ˆ˜์ด๋‹ค (5*2 = 10) 10์€ 10์˜ ๋ฐฐ์ˆ˜์ด๋‹ค(10*1 = 10) 6์€ 1์˜ ๋ฐฐ์ˆ˜์ด๋‹ค(1*6 = 6) 20์€ 1, 2, 4,5,10,20์˜ ๋ฐฐ์ˆ˜์ด๋‹ค. ๋‹ค www.acmicpc.net #include using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { long long int A, B; cin >> A>>B; cout 2021. 11. 4.