(SRM691) PlusOneGame(div2_300)
//각 숫자에 해당하는 인덱스의 배열을 만들고 해당 숫자가 나오는 갯수 만큼 횟수를 증가시켰다. 그런 후 출력시 그 갯수만큼 숫자를 출력하였다. +는 현재 숫자가 존재하는지 유무와 관계없이 i루프를 돌면서 계속 추가시켰다 또한 string t; t=t+'+' 를 하면 현재 문자열 맨 앞에 해당 '+'가 추가 되는 것을 명심하자 #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<string> #include<bits/stdc++.h> using namespace std; class Plusonegame{ public: int cal[20]; public: string getorder(string s){ int n = s.size(); memset(cal, 0, sizeof(cal)); int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == '+')cnt++; else cal[s[i] - '0']++; } string ans; for (int i = 0; i <= 9; i++) { for (int j = 0; j < cal[i]; j++)ans = ans + char(i + '0'); if (cnt){ ans = ans + '+'; cnt--; } } while (cnt){ ans = ans + '+'; cnt--; } return ans; } };