[TIL] 111 ๊ณ„์ˆ˜์ •๋ ฌ(Comparison Sort), StreamWriter StreamReader

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: ,


Comparison Sort StreamWriter StreamReader
StreamWriter(Console.OpenStandardOutput())



๊ณ„์ˆ˜์ •๋ ฌ(Comparison Sort)

๊ณ„์ˆ˜ ์ •๋ ฌ์€ ์ฃผ์–ด์ง„ ์ˆ˜์˜ ๋ฒ”์œ„๊ฐ€ ์ž‘์€ ๊ฒฝ์šฐ์— ๋งค์šฐ ํšจ์œจ์ ์ธ ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜


// ์ˆซ์ž ์ž…๋ ฅ ๋ฐ›๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ, ์ถœ๋ ฅ
var sw = new StreamWriter(Console.OpenStandardOutput());

int testcase = Convert.ToInt32(Console.ReadLine());
int[] Narr= new int[100001];
for (int i = 0; i < testcase; i++)
{
    Narr[Convert.ToInt32(Console.ReadLine())]++;
}
for (int i = 1; i < Narr.Length; i++)
{
    for (int j = 0; j < Narr[i]; j++)
    {
        sw.WriteLine(i);
    }
}
sw.Close();


StreamWriter(Console.OpenStandardOutput())

C#์—์„œ ํŒŒ์ผ์„ ์ฝ๊ณ  ์“ฐ๊ธฐ ์œ„ํ•œ ์ŠคํŠธ๋ฆผ์œผ๋กœ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ๋กœ streamWriter์‚ฌ์šฉ


var sw = new StreamWriter(Console.OpenStandardOutput());
sw.WriteLine(i);
sw.Flush(); sw.Close();







StreamWriter์™€ StreamReader


var path = "๊ฒฝ๋กœ";

//ํŒŒ์ผ ์“ฐ๊ธฐ
var sw = new StreamWriter(path);
sw.Write("1");
sw.WriteLine("1");
sw.Close();

//ํŒŒ์ผ ์ฝ๊ธฐ
var sr = new StreamReader(path);
{ }
sr.Close();

  • ๋‹ค์Œ์— ๊ฒŒ์ž„ ํ”„๋กœ์ ํŠธ ์‹œ ํŒŒ์ผ ์ฝ๊ณ ์“ธ๋•Œ ๋” ์ž์„ธํ•˜๊ฒŒ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ.

์žก๋‹ด, ์ผ๊ธฐ?

๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ ๋•Œ๋ฌธ์— streamWriter์„ ์‚ฌ์šฉํ•ด ๋ณด๊ณ 
ํŒŒ์ผ์„ ์ฝ๊ณ  ์“ฐ๋Š” ์ŠคํŠธ๋ฆผ StreamReader์™€ StreamWriter์— ๋Œ€ํ•˜์—ฌ ์ •๋ฆฌ
์ด๋ ฅ์„œ ์ •๋ฆฌ, ์ž์†Œ์„œ ์ž‘์„ฑ, ๋ฉด์ ‘์ค€๋น„์ค‘, ์ฝ”ํ…Œ




๐Ÿ“”

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ