diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98bb375 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.exe +*.vcxproj \ No newline at end of file diff --git "a/10808_\354\225\214\355\214\214\353\262\263\352\260\234\354\210\230.cpp" "b/10808_\354\225\214\355\214\214\353\262\263\352\260\234\354\210\230.cpp" new file mode 100644 index 0000000..f1405c7 --- /dev/null +++ "b/10808_\354\225\214\355\214\214\353\262\263\352\260\234\354\210\230.cpp" @@ -0,0 +1,24 @@ +#include + +using namespace std; + +typedef long long ll; + +string str; +int arr[26]; + +int main() +{ + cin >> str; + for(char a : str) + { + arr[a - 'a']++ ; + } + + for (int i = 0; i < 26; i++) + { + cout << arr[i] << " "; + } + + return 0; +} \ No newline at end of file diff --git "a/10988_\355\214\260\353\246\260\353\223\234\353\241\254\355\231\225\354\235\270\355\225\230\352\270\260.cpp" "b/10988_\355\214\260\353\246\260\353\223\234\353\241\254\355\231\225\354\235\270\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..f1f6f35 --- /dev/null +++ "b/10988_\355\214\260\353\246\260\353\223\234\353\241\254\355\231\225\354\235\270\355\225\230\352\270\260.cpp" @@ -0,0 +1,35 @@ +#include + +using namespace std; + +// string s; +// int cnt; + +// int main() +// { +// cin >> s; + +// for(int i = 0; i < s.length()/2 ; i++) +// { +// if(s[i] != s[s.length() - 1 - i]) +// { +// cnt += 1; +// } +// } + +// if(cnt == 0) cout << 1; +// else cout << 0; + +// return 0; +// } + +string s, tmp; +int main() +{ + cin >> s; + tmp = s; + reverse(tmp.begin(), tmp.end()); + if(tmp == s) cout << 1<< "\n"; + else cout << 0 << "\n"; + return 0; +} \ No newline at end of file diff --git "a/1159_\353\206\215\352\265\254\352\262\275\352\270\260.cpp" "b/1159_\353\206\215\352\265\254\352\262\275\352\270\260.cpp" new file mode 100644 index 0000000..c230a85 --- /dev/null +++ "b/1159_\353\206\215\352\265\254\352\262\275\352\270\260.cpp" @@ -0,0 +1,29 @@ +#include + +using namespace std; + +int n, cnt[26]; +string name, tmp; + +int main() +{ + cin >> n; + + for (int i = 0; i < n; i++) + { + cin >> name; + cnt[name[0] - 'a'] ++; + } + + for(int i=0; i < 26; i++) + { + if(cnt[i] >= 5) + { + tmp += (i + 'a'); + } + } + if(tmp.size() != 0) cout << tmp << "\n"; + else cout << "PREDAJA" << "\n"; + + return 0; +} \ No newline at end of file diff --git "a/2309_\354\235\274\352\263\261\353\202\234\354\237\201\354\235\264.cpp" "b/2309_\354\235\274\352\263\261\353\202\234\354\237\201\354\235\264.cpp" new file mode 100644 index 0000000..966de09 --- /dev/null +++ "b/2309_\354\235\274\352\263\261\353\202\234\354\237\201\354\235\264.cpp" @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int a[10]; + +int main() +{ + int sum = 0; + + for(int i= 0; i < 9 ; i++){ + cin >> a[i]; + sum += a[i]; + } + + sort(a, a+9); + + for (int i = 0; i < 9; i++) + { + for (int j = i + 1; j < 9; j++) + { + if ((sum - (a[i] + a[j])) == 100) + { + for (int k = 0; k < 9; k++) + { + if (i == k || j == k) + continue; + cout << a[k] << "\n"; + } + return 0; + } + } + } + return 0; +} \ No newline at end of file diff --git "a/2559_\354\210\230\354\227\264.cpp" "b/2559_\354\210\230\354\227\264.cpp" new file mode 100644 index 0000000..d977268 --- /dev/null +++ "b/2559_\354\210\230\354\227\264.cpp" @@ -0,0 +1,26 @@ +#include + +using namespace std; + +typedef long long ll; + +int n, k, tmp, psum[100001], ret = -10000004; + +int main() +{ + cin >> n >> k; + for(int i = 1; i <= n; i++) + { + cin >> tmp; + psum[i] = psum[i - 1] + tmp; + } + + for(int i = k; i <= n; i++) + { + ret = max(ret, psum[i] - psum[i - k]); + } + + cout << ret << "\n"; + + return 0; +} \ No newline at end of file diff --git "a/2979_\355\212\270\353\237\255\354\243\274\354\260\250.cpp" "b/2979_\355\212\270\353\237\255\354\243\274\354\260\250.cpp" new file mode 100644 index 0000000..48bbe4b --- /dev/null +++ "b/2979_\355\212\270\353\237\255\354\243\274\354\260\250.cpp" @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int a, b, c, ans = 0; +int arr[101]; + +int main() +{ + cin >> a >> b >> c; + for (int i = 0; i < 3; i++) + { + int start, end; + cin >> start >> end; + for(int j = start ; j < end; j ++) + { + arr[j] += 1; + } + } + + for(int i = 1; i <= 100; i ++) + { + if(arr[i] == 1) ans += arr[i] * a; + else if(arr[i] == 2) ans += arr[i] * b; + else ans += arr[i] * c; + } + + cout << ans; + return 0; +} + diff --git "a/9375_\355\214\250\354\205\230\354\231\225 \354\213\240\355\225\264\353\271\210.cpp" "b/9375_\355\214\250\354\205\230\354\231\225 \354\213\240\355\225\264\353\271\210.cpp" new file mode 100644 index 0000000..fa7b57b --- /dev/null +++ "b/9375_\355\214\250\354\205\230\354\231\225 \354\213\240\355\225\264\353\271\210.cpp" @@ -0,0 +1,33 @@ +#include + +using namespace std; + +int t, n; +string a,b; + +int main() +{ + cin >> t; + while (t--) + { + map wear; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a >> b; + wear[b] ++; + } + + long long tmp = 1; + + for (auto w : wear) + { + tmp *= ((long long)w.second + 1); + } + + tmp -= 1; + + cout << tmp << "\n"; + + } +} \ No newline at end of file diff --git "a/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220(\353\213\244\354\213\234).cpp" "b/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220(\353\213\244\354\213\234).cpp" new file mode 100644 index 0000000..e613f48 --- /dev/null +++ "b/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220(\353\213\244\354\213\234).cpp" @@ -0,0 +1,37 @@ +#include + +using namespace std; + +int n; +string file, pattern, pre, suf; +int main() +{ + cin >> n; + cin >> pattern; + + int pos = pattern.find("*"); + pre = pattern.substr(0, pos); + suf = pattern.substr(pos + 1); + + for (int i = 0; i < n; i++) + { + cin >> file; + if(pre.size() + suf.size() > file.size()) + { + cout << "NE" <<"\n"; + } + else + { + if(pre == file.substr(0, pre.size()) && suf == file.substr(file.size() - suf.size())) + { + cout << "DA" << "\n"; + } + else + { + cout << "NE" << "\n"; + } + } + } + + return 0; +} \ No newline at end of file diff --git "a/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220.cpp" "b/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220.cpp" new file mode 100644 index 0000000..3c04bf0 --- /dev/null +++ "b/9996_\355\225\234\352\265\255\354\235\264\352\267\270\353\246\254\354\232\270\353\225\220.cpp" @@ -0,0 +1,47 @@ +#include + +using namespace std; + +int main() +{ + int n; + string pattern; + vector files, answer; + + cin >> n; + cin >> pattern; + for(int i = 0; i < n; i++) + { + string s; + cin >> s; + files.push_back(s); + } + + char start, end; + start = pattern[0]; + end = pattern[pattern.length() - 1]; + + for(int i = 0; i < n - 1; i++) + { + + if(files[i][0] == start && files[i][files[i].length() - 1] == end) + { + cout << "DA\n"; + } + else + { + cout << "NE\n"; + } + } + + if(files[n-1][0] == start && files[n-1][files[n-1].length() - 1] == end) + { + cout << "DA"; + } + else + { + cout << "NE"; + } + + return 0; +} \ No newline at end of file diff --git a/Algo.vcxproj b/Algo.vcxproj deleted file mode 100644 index b18a93c..0000000 --- a/Algo.vcxproj +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {0a79eafa-2440-4cec-882d-5ae9a4c2284b} - Algo - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/Algo.vcxproj.filters b/Algo.vcxproj.filters deleted file mode 100644 index b6dbf47..0000000 --- a/Algo.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - 소스 파일 - - - \ No newline at end of file diff --git a/Algo.vcxproj.user b/Algo.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/Algo.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/BASE/.vscode/c_cpp_properties.json b/BASE/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..3066bce --- /dev/null +++ b/BASE/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.16299.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/BASE/.vscode/tasks.json b/BASE/.vscode/tasks.json new file mode 100644 index 0000000..2470534 --- /dev/null +++ b/BASE/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe 활성 파일 빌드", + "command": "C:\\MinGW\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "C:\\MinGW\\bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "컴파일러: C:\\MinGW\\bin\\g++.exe" + } + ] +} \ No newline at end of file diff --git "a/BASE/\353\210\204\354\240\201\355\225\251.cpp" "b/BASE/\353\210\204\354\240\201\355\225\251.cpp" new file mode 100644 index 0000000..daba9f8 --- /dev/null +++ "b/BASE/\353\210\204\354\240\201\355\225\251.cpp" @@ -0,0 +1,46 @@ +#include + +using namespace std; + +typedef long long ll; + +int a[100004], b, c, psum[100004], n, m; + +// 시간 초과 발생 O(10만 * 10만) +// int main() +// { +// cin >> n >> m; +// for(int i = 1; i <= n; i++) +// { +// cin >> a[i]; +// } + +// for(int i = 0; i < m; i++) +// { +// cin >> b >> c; +// int sum = 0; + +// for(int j = b; j <= c; j++) sum += a[j]; + +// cout << sum << "\n"; +// } +// return 0; +// } + +int main() +{ + cin >> n >> m; + for (int i = 1; i <= n; i++) + { + cin >> a[i]; + psum[i] = psum[i - 1] + a[i]; + } + + for (int i = 0; i < m; i++) + { + cin >> b >> c; + cout << psum[c] - psum[b - 1] << "\n"; + } + + return 0; +} \ No newline at end of file diff --git "a/BASE/\354\210\234\354\227\264.cpp" "b/BASE/\354\210\234\354\227\264.cpp" new file mode 100644 index 0000000..c7629d7 --- /dev/null +++ "b/BASE/\354\210\234\354\227\264.cpp" @@ -0,0 +1,41 @@ +#include + +using namespace std; + +int a[3] = {1, 2, 3}; +vector v; + +void printV(vector &v) +{ + for (int i = 0; i < v.size(); i++) + { + cout << v[i] << " "; + } + cout << "\n"; +} + +void Permutation(int n, int r, int level) +{ + if(r == level) + { + printV(v); + return; + } + for(int i = level; i < n; i ++) + { + swap(v[i], v[level]); + Permutation(n, r, level + 1); + swap(v[i], v[level]); + } + return; +} + +int main() +{ + for(int i = 0; i < 3; i++) + { + v.push_back(a[i]); + } + Permutation(3, 3, 0); + return 0 ; +} \ No newline at end of file diff --git a/StringTest.cpp b/StringTest.cpp new file mode 100644 index 0000000..f2b6edd --- /dev/null +++ b/StringTest.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +vector split(string input, string delimiter) +{ + vector ret; + long long pos = 0; + string token = ""; + + while((pos = input.find(delimiter)) != string::npos) + { + token = input.substr(0, pos); + ret.push_back(token); + input.erase(0, pos + delimiter.length()); + + cout << "input : " << input << "\n"; + } + + ret.push_back(input); + return ret; +} + + +int main() +{ + string s = "aa.bb.cc.dd.ee.ff.gg"; + vector a = split(s, "."); + + cout << a[3] << "\n"; + + // for(string b : a) cout << b << "\n"; +} + diff --git a/desktop.ini b/desktop.ini deleted file mode 100644 index d957fd1..0000000 --- a/desktop.ini +++ /dev/null @@ -1,4 +0,0 @@ -[ViewState] -Mode= -Vid= -FolderType=Generic diff --git "a/\352\260\234\353\205\220\354\240\225\353\246\254/\353\210\204\354\240\201\355\225\251.md" "b/\352\260\234\353\205\220\354\240\225\353\246\254/\353\210\204\354\240\201\355\225\251.md" new file mode 100644 index 0000000..4ef9edf --- /dev/null +++ "b/\352\260\234\353\205\220\354\240\225\353\246\254/\353\210\204\354\240\201\355\225\251.md" @@ -0,0 +1,113 @@ +## 누적합 + +미리 요소들의 합을 저장해 두는 누적된 수의 합을 의미 + +앞에서부터 더하는 **prefix sum** 과 뒤에서 부터 더하는 suffix sum이 있지만 주로 **prefix sum**만 나온다 . + + 누적합은 구간쿼리에 대응하기 쉽다. + +구간쿼리 : 정적배열 / 동적배열(어떤 순간에 구간안에 있는 요소가 변한다.) + +- 정적배열 : 구간합 + +- 동적배열 : 트리(세그먼트트리, 펜윅트리) + + + +**예시 문제** + +자연수로 이루어진 N개의 카드를 주며 M개의 질문을 던진다. + +질문은 나열한 카드 중 A 번째부터 B번째 까지의 합을 구하는것이다. + +입력) + +수의 개수 N, 합을 구해야 하는 횟수 M, 그 이후에 N개의 수가 주어진다. 수는 100이하의 자연수 + +그 이후 M개의 줄에는 합을 구해야 하는 구간 A, B가 주어진다. + +출력) + +M개의 줄에 A부터 B까지의 합을 구하라 + +범위) + +1 <= N, M <= 100,000 + +1 <= A <= B <= N + +예제 입력 + +``` +8 3 +1 2 3 4 5 6 7 8 +1 4 +1 5 +3 5 +``` + +예제 출력 + +``` +10 +15 +12 +``` + +**[시간초과] O(10만 * 10만)** + +```c++ +#include +using namespace std; +typedef long long ll; +int a[100004], b, c, psum[100004], n, m; + +// 시간 초과 발생 O(10만 * 10만) +int main() +{ + cin >> n >> m; + for(int i = 1; i <= n; i++) + { + cin >> a[i]; + } + + for(int i = 0; i < m; i++) + { + cin >> b >> c; + int sum = 0; + + for(int j = b; j <= c; j++) sum += a[j]; + + cout << sum << "\n"; + } + return 0; +} +``` + +**[구간합 이용]** + +```c++ +#include +using namespace std; +typedef long long ll; +int a[100004], b, c, psum[100004], n, m; + +int main() +{ + cin >> n >> m; + for (int i = 1; i <= n; i++) + { + cin >> a[i]; + psum[i] = psum[i - 1] + a[i]; + } + + for (int i = 0; i < m; i++) + { + cin >> b >> c; + cout << psum[c] - psum[b - 1] << "\n"; + } + + return 0; +} +``` + diff --git "a/\352\260\234\353\205\220\354\240\225\353\246\254/\353\254\270\354\236\220\354\227\264.md" "b/\352\260\234\353\205\220\354\240\225\353\246\254/\353\254\270\354\236\220\354\227\264.md" new file mode 100644 index 0000000..49b1563 --- /dev/null +++ "b/\352\260\234\353\205\220\354\240\225\353\246\254/\353\254\270\354\236\220\354\227\264.md" @@ -0,0 +1,124 @@ +## 문자열 + +- reverse : 원래의 문자열을 바꿔준다. + + begin과 end를 통해 전체를 바꿀 수 있고 s.begin(), s.begin() + 3 처럼 부분만 바꿀 수 있다. + +- substr : 시작지점으로 부터 몇개의 문자열을 뽑아낸다. + +- find : 어떠한 문자열이 들어있나 찾을 수 있다. 가장 처음 찾은 문자열의 위치를 반환한다. + + ​ 찾지못하면 문자열의 끝 위치인string::npos를 반환 + +- split : 지원을 안하니 외워 놓기 - 리스트로 받아서 주로 사용 + +## [reverse] + +```c++ +string s = "Hello World"; +int main() +{ + reverse(s.begin(), s.end()); + cout << s ; + return 0; +} +``` + +``` +>>> dlroW olleH +``` + +```c++ +string s = "Hello World"; + +int main() +{ + reverse(s.begin()+ 1, s.begin()+ 4); + cout << s ; + + return 0; +} +``` + +``` +>>> Hlleo World +``` + +## [substr] + +```c++ +string s = "Hello World"; + +int main() +{ + cout << s.substr(0, 4); +} +``` + +``` +>>> Hell +``` + +## [find] + +```c++ +string s = "Hello World"; + +int main() +{ + cout << s.find("o") << "\n"; + cout << s.find("k") << "\n"; + if(s.find("k") == string::npos) + { + cout << "NO"; + } +} +``` + +``` +>>> 4 +>>> 4294967295 +>>> NO +``` + +## [split] + +```c++ +vector split(string input, string delimiter) +{ + vector ret; + long long pos = 0; + string token = ""; + + while((pos = input.find(delimiter)) != string::npos) + { + token = input.substr(0, pos); + ret.push_back(token); + input.erase(0, pos + delimiter.length()); + } + ret.push_back(input); + return ret; +} +``` + +예시) + +```c++ +int main() +{ + string s = "aa.bb.cc.dd.ee.ff.gg"; + vector a = split(s, "."); + + for(string b : a) cout << b << "\n"; +} +``` + +``` +>>> aa +>>> bb +>>> cc +>>> dd +>>> ee +>>> ff +>>> gg +``` \ No newline at end of file diff --git "a/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\353\243\214\352\265\254\354\241\260.md" "b/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\353\243\214\352\265\254\354\241\260.md" new file mode 100644 index 0000000..74a8354 --- /dev/null +++ "b/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\353\243\214\352\265\254\354\241\260.md" @@ -0,0 +1,4 @@ +## 자료구조 + +### pair 와 tuple + diff --git "a/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\354\243\274 \354\202\254\354\232\251\355\225\230\353\212\224 \353\235\274\354\235\264\353\270\214\353\237\254\353\246\254.md" "b/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\354\243\274 \354\202\254\354\232\251\355\225\230\353\212\224 \353\235\274\354\235\264\353\270\214\353\237\254\353\246\254.md" new file mode 100644 index 0000000..7894ed5 --- /dev/null +++ "b/\352\260\234\353\205\220\354\240\225\353\246\254/\354\236\220\354\243\274 \354\202\254\354\232\251\355\225\230\353\212\224 \353\235\274\354\235\264\353\270\214\353\237\254\353\246\254.md" @@ -0,0 +1,3 @@ +### 자주 사용하는 라이브러리 + +#### [] \ No newline at end of file diff --git "a/\355\214\260\353\246\260\353\223\234\353\241\254\352\270\260\354\266\234.cpp" "b/\355\214\260\353\246\260\353\223\234\353\241\254\352\270\260\354\266\234.cpp" new file mode 100644 index 0000000..3a775d9 --- /dev/null +++ "b/\355\214\260\353\246\260\353\223\234\353\241\254\352\270\260\354\266\234.cpp" @@ -0,0 +1,29 @@ +#include + +using namespace std; + +string s, tmp; +int cnt = 0; + +int main() +{ + cin >> s; + tmp = s; + reverse(tmp.begin(), tmp.end()); + + if(s == tmp) + { + cout << 0; + } + else + { + for(int i = 0; i < s.length(); i++) + { + if(s[i] != tmp[i]) cnt++; + } + + cout << cnt / 2; + } + + return 0; +} \ No newline at end of file