C++
-
백준 11656 - 접미사 배열백준 algorithm 2020. 3. 13. 12:25
=> substr 함수의 사용을 할줄 아는지 묻는 문제이다. => string이 들어가 있는 배열 역시 sort함수를 통해 정렬 할 수 있다. (연산자 재정의 no need) => for문을 쓸 경우 length()같은 함수를 for문에 쓸 경우 시간이 더 걸리게 된다. 그 이전에 int limit = s.length() 를 해주어야 시간을 save 할 수 있게 된다. #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin>>s; vector arr; int limit=s.length(..
-
백준 10824 - 네 수백준 algorithm 2020. 3. 11. 23:31
=> stoll 함수를 사용할 줄 아는지 묻는 문제이다. #include #include using namespace std; long long merge(long num1, long num2) { string t1 =to_string(num1) + to_string(num2); long long val = stoll(t1); return val; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long A, B, C, D; cin>> A >> B >> C>>D; long long answer = merge(A, B); answer += merge(C,D); cout
-
백준 11655 - ROT13백준 algorithm 2020. 3. 11. 23:10
=> 공백이 포함된 문자열을 입력받아 각 문자마다 아스키코드로 13을 더해주면 된다. => 소문자와 대문자의 범위를 벗어날 때의 예외처리를 해주어야한다. => 본인은 소문자의 아스키코드를 int형으로 받아 따로 처리해주었다. // // main.cpp // Baekjoon // // Created by 이준후 // Copyright © 2020 이준후. All rights reserved. // #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; getline(cin, s); for(int i=0; i= 65 && s[i..
-
백준 10808 - 알파벳 개수백준 algorithm 2020. 3. 10. 01:45
=>string을 입력받은 후에 만들어놓은 배열에 하나씩 추가해준다. =>아스키코드를 통해 index를 접근하면 된다. #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int alphabet[26]={0}; for(int i=0; i
-
백준 1850 - 최대공약수백준 algorithm 2020. 3. 10. 01:19
=>실제로 입력받은 갯수로 1로 이루어진 숫자로 최대 공약수를 만들면 안된다. =>입력 받은 값의 최대 공약수를 구한 다음 그 값을 limit으로 1을 출력하면 된다. #include #include #include #include #include using namespace std; int gcd(long long a, long long b) { long long c; while (b != 0) { c = a % b; a = b; b = c; } return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long A,B; cin>>A>>B; int limit=gcd(A,B); for..
-
백준 5622 - 다이얼백준 algorithm 2020. 3. 8. 17:43
=> case 문으로 단순히 더하면 되는 문제이다. // // main.cpp // Baekjoon // // Created by 이준후 // Copyright © 2020 이준후. All rights reserved. // #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string dial; cin >> dial; int answer=0; for(int i=0; i
-
백준 1918 - 후위 표기식백준 algorithm 2020. 3. 8. 17:29
후위표기식2 와 달리 계산하는 것이 아닌 중위표기식을 후위표기식으로 바꾸는 방법이다. =>연산자를 stack에 넣는 것으로 한다. => ( 여는 괄호가 나오면 여는 괄호를 무조건 stack에 쌓는다. => ) 닫는 괄호가 나오면 (여는 괄호가 나올 때까지 stack을 pop하며 찾는다. => stack안에 연산자들은 위에 있는 연산자가 아래에 있는 연산자보다 우선순위가 높아야한다. (같아서도 안됨!) => ( 여는 괄호의 경우를 감안하여 코드를 짜야한다. *** 왜 나는 한 문제를 푸는데 기본적으로 한시간이 쓰이는지.... 조금 더 빨리 답을 찾아가는 습관을 들여야겠다. #include #include #include #include #include using namespace std; stack st;..