: ๋ฌธ์ ๋ฅผ ์ฝ์ผ๋ฉด์, ์กฐ๊ฑด n์ <100 ๋ณด๊ณ , ์ด๋ค ํ์
์ผ๋ก ํ์ด์ผ
ํ ์ง๋ฅผ ํ๋จํ์ด์ผ ํจ.
int : 10์ 9์น
long long : 10์ 18์น
int ํ์ 10์ 9์น
long long ํ์ 10์ 18์น
-> ์ ์ํ์ผ๋ก ์ต์ ์ ์๋ฆฌ์ 100์ ์ปค๋ฒ์น ์ ์์.
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <map>
#include <future>
#include <thread>
#include <numeric>
#include <stack>
#include <queue>
#include <memory>
#include <set>
#include <string>
int main()
{
// ์ ์ผํ ๊ฐ์ด์ด์ผ ํจ.
// ์ค๋ฆ์ฐจ์์ผ๋ก
// ๋ฌธ์ ํ๋์ฉ ํ์ธํ๋ค๊ฐ
// '0' ~ '9' ๊น์ง์ผ ๊ฒฝ์ฐ์๋ง ์ถ๊ฐ
// ๋ถ๋ณ์ ํ์ํ๋ค.
// ์ฐ์์ ์ผ ๊ฒฝ์ฐ์๋ +
// ์๋๋ฉด ์ข
๋ฃ
multiset<long long>s;
int num;
cin >> num;
string word;
for(int i = 0; i < num; ++i)
{
cin >> word;
string temp = "";
bool check = false;
for (char &iter : word)
{
if (iter >= '0' && iter <= '9')
{
check = true;
// ๋ง์ฝ ๋งจ์์ด 0์ด๋ผ๊ณ ํ๋ฉด ์ ๊ฑฐํ์.
if (temp.size() == 1 && temp.front() == '0')
{
temp.pop_back();
}
temp += iter;
}
// ์ซ์๊ฐ ์๋๋ฐ,
else
{
if (check == true)
{
//s.insert(temp);
s.insert(stol(temp));
temp.clear();
temp = "";
}
check = false;
}
}
// ๋ง์ง๋ง ๋ฌธ์๊ฐ ์ซ์์ผ ๊ฒฝ์ฐ // ์์ธ ์ฒ๋ฆฌ์.
if (check == true)
{
s.insert(stol(temp));
}
}
for (auto &iter : s)
{
cout << iter << endl;
}
}
#include <iostream>
#include <list>
using namespace std;
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
// 2870 ์ํ ์์
// 00:27 ~ 00:47 -> 6ํผ์ผํธ์์ ํ๋ฆผ.
bool compare(string &s1, string &s2)
{
//์ฌ์ด์ฆ๊ฐ ๊ฐ์ฅ ์์ ๊ฒ์ ๊ธฐ์ค์ผ๋ก ํด์
// ์ํ ๋๋ฆฌ๋ฉด์ ์๊ธ์๊ฐ ์์ ๊ธ์๊ฐ ์๋ก ์์ผ ํจ.
int size1 = s1.size();
int size2 = s2.size();
int mmin = min(size1, size2);
if (size1 == size2)
{
for (int i = 0; i < mmin; ++i)
{
if (s1[i] == s2[i])
{
continue;
}
return s1[i] < s2[i];
}
}
else
{
return size1 < size2;
}
return false;
}
int main()
{
vector<string>v;
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
string ss;
cin >> ss;
bool check = false;
string temp = "";
// * 10 ํ๋ฉด์ ์ถ๊ฐํ์
// + value
for (int j = 0; j < ss.length(); ++j)
{
if (ss[j] >= '0' && ss[j] <= '9')
{
check = true;
if (temp.size() == 1 && temp.front() == '0')
{
temp.pop_back();
}
temp += ss[j];
//cout << temp << endl;
}
else
{
//temp ๊ฐ์ ๊บผ๋ด๋ฉด์ ์ซ์๋ก ๋ง๋ค๊ณ ์ด๋ฅผ
if (check == true)
{
v.push_back(temp);
temp = "";
}
check = false;
}
}
//๋ง์ง๋ง ๋ถ๋ถ ์์ธ ์ฒ๋ฆฌ
if (check == true)
{
v.push_back(temp);
temp = "";
}
}
sort(v.begin(), v.end() , compare);
for (auto iter : v)
{
cout << iter << '\n';
}
}
: 6ํผ์ผํธ์์ ํ๋ฆผ.
#include <iostream>
#include <list>
using namespace std;
#include <map>
#include <vector>
#include <string>
#include <queue>
// 2870 ์ํ ์์
// 00:27 ~ 00:47 -> 6ํผ์ผํธ์์ ํ๋ฆผ.
int main()
{
// ์ซ์์ ์๋ฌธ์๋ก ๋์ด ์๋ ๊ธ์ n์ค
// ์ฌ๊ธฐ์ ์ซ์๋ฅผ ๋ชจ๋ ์ฐพ์์ , ์ซ์๋ฅผ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ฆฌํด์ผ ํจ.
// ์ซ์์ ์์ 0์ด ์๋ ๊ฒฝ์ฐ, ์๋ตํ ์ ์์.
// 43 0 2 2 231233
priority_queue<long long , vector<long long>, greater<long long>>pq;
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
string ss;
cin >> ss;
bool check = false;
string temp = "";
// * 10 ํ๋ฉด์ ์ถ๊ฐํ์
// + value
for (int j = 0; j < ss.length(); ++j)
{
if (ss[j] >= '0' && ss[j] <= '9')
{
check = true;
temp += ss[j];
//cout << temp << endl;
}
else
{
//temp ๊ฐ์ ๊บผ๋ด๋ฉด์ ์ซ์๋ก ๋ง๋ค๊ณ ์ด๋ฅผ
if (check == true)
{
long long num = 0;
for (auto iter : temp)
{
num = num * 10 + (iter - '0');
}
pq.push(num);
temp = "";
}
check = false;
}
}
//๋ง์ง๋ง ๋ถ๋ถ ์์ธ ์ฒ๋ฆฌ
if (check == true)
{
long long num = 0;
for (auto iter : temp)
{
num = num * 10 + (iter - '0');
}
pq.push(num);
temp = "";
}
}
while (!pq.empty())
{
cout << pq.top() << endl;
pq.pop();
}
}