We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
소스 코드
마이너스를 만나면 다음 마이너스를 만날 때까지 괄호를 씌워 덧셈 값을 뺄셈 값으로 바꾸게 함
ex. 40-30+40-20+40 -> 40-(30+40)-(20+40) -> 최소
편의상 뺄셈은 양수와 음수의 합으로 보고, 다음 음수를 만날 때까지 양수를 음수로 바꿈 예시: 40-30+40 -> 40+(-30) + (-40)
string str; int chk = 0; // 이전 부호의 위치를 저장하고 있음. int sum = 0; bool ck = false; // 음수를 만났는지를 체크 for(int i = 0; i<str.length(); ++i) { if(str[i] == '-' || str[i] == '+') { // 부호를 만나면 이전 번호 추출 int num = stoi(str.substr(chk, i)); if(num < 0) { // 음수를 만나면 ck = true로 set ck = true; }else if(ck) { // 음수를 만났으면 양수를 음수로 만듦. num = -num; } sum += num; // 가산 chk = i; // 부호 위치 갱신 } }
The text was updated successfully, but these errors were encountered:
minsoo0715
No branches or pull requests
1541: 잃어버린 괄호
소스 코드
아이디어
마이너스를 만나면 다음 마이너스를 만날 때까지 괄호를 씌워 덧셈 값을 뺄셈 값으로 바꾸게 함
ex. 40-30+40-20+40 -> 40-(30+40)-(20+40) -> 최소
구현
편의상 뺄셈은 양수와 음수의 합으로 보고, 다음 음수를 만날 때까지 양수를 음수로 바꿈
예시: 40-30+40 -> 40+(-30) + (-40)
The text was updated successfully, but these errors were encountered: