๐Ÿค—2870. ์ˆ˜ํ•™ ๋ฌธ์ œ _ ๋ฌธ์ œ์˜ ์กฐ๊ฑด์„ ๋ณด๊ณ , ์–ด๋–ค ํƒ€์ž…์„ ์‚ฌ์šฉํ• ๊ฑด์ง€ ํŒŒ์•…์„ ํ•ด์•ผ ํ•จ@

phoenixKimยท2022๋…„ 9์›” 2์ผ
0

๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ชฉ๋ก ๋ณด๊ธฐ
97/174

๐Ÿคชํ’€์ด์ „๋žต

: ๋ฌธ์ œ๋ฅผ ์ฝ์œผ๋ฉด์„œ, ์กฐ๊ฑด n์„ <100 ๋ณด๊ณ , ์–ด๋–ค ํƒ€์ž…์œผ๋กœ ํ’€์–ด์•ผ
ํ• ์ง€๋ฅผ ํŒ๋‹จํ–ˆ์–ด์•ผ ํ•จ.

๐Ÿคช์•Œ์•„์•ผ ํ• ์ .

  • int์™€ long long์ด ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ์ž๋ฆฟ์ˆ˜

    int : 10์˜ 9์Šน
    long long : 10์˜ 18์Šน

๋งž์™œํ‹€??

  • ๋ฌธ์ œ๋ฅผ ์ฝ์ž๋งˆ์ž ์–ด๋–ค ํƒ€์ž…์„ ์‚ฌ์šฉํ• ์ง€๋ฅผ ์บ์น˜๋ฅผ ํ•ด์•ผ ํ–ˆ์Œ.

    int ํ˜•์€ 10์˜ 9์Šน
    long long ํ˜•์€ 10์˜ 18์Šน

-> ์ •์ˆ˜ํ˜•์œผ๋กœ ์ตœ์•…์˜ ์ž๋ฆฌ์ˆ˜ 100์„ ์ปค๋ฒ„์น  ์ˆ˜ ์—†์Œ.

multiSet ์œผ๋กœ ์ ‘๊ทผํ•œ ์ตœ๊ทผ ํ’€์ด 231215

  • ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ ๋ฐœ์ƒ.
#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();
	}

}
profile
๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด