More actions
imported>skywave No edit summary |
(Repair batch-0007 pages from live compare) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 27: | Line 27: | ||
} | } | ||
static void Main(string | static void Main(string[] args) | ||
{ | { | ||
List<pair> p = new List<pair>(); | List<pair> p = new List<pair>(); | ||
| Line 33: | Line 33: | ||
pair temp; | pair temp; | ||
string | string[] s; | ||
string line; | string line; | ||
StreamReader sr = new StreamReader(@"C:\test.txt"); | StreamReader sr = new StreamReader(@"C:\test.txt"); | ||
| Line 46: | Line 46: | ||
if (j == p.Count) | if (j == p.Count) | ||
{ | { | ||
temp.word = s | temp.word = s[i]; | ||
temp.count = 1; | temp.count = 1; | ||
p.Add(temp); | p.Add(temp); | ||
break; | break; | ||
} | } | ||
if (p | if (p[j].word == s[i]) | ||
{ | { | ||
temp.word = p | temp.word = p[j].word; | ||
temp.count = p | temp.count = p[j].count + 1; | ||
p | p[j] = temp; | ||
break; | break; | ||
} | } | ||
| Line 64: | Line 64: | ||
for (int i = 0; i < p.Count; i++) | for (int i = 0; i < p.Count; i++) | ||
{ | { | ||
if (p | if (p[i].word == null) break; | ||
Console.Write(p | Console.Write(p[i].word+" "+p[i].count+"\n"); | ||
} | } | ||
Console.Read(); | Console.Read(); | ||
| Line 72: | Line 72: | ||
} | } | ||
== r0(13/05/06) == | == r0(13/05/06) == | ||
정모/2013.5.6/CodeRace#s-2.2 | |||
Latest revision as of 01:32, 27 March 2026
조영준의 하위 문서입니다.
개요
- 언어 : C#
- 느낀 점
- List를 까먹고 배열을 썼다가 피를 봤었습니다.
- Compare은 인터페이스를 구현시킨건가? 음...
- C#은 이런 저런 일을 하는데 편안한 기능이 많다보니 다른 언어로 짠 다른 분들의 코드를 보니 게을러지는 느낌이 살짝.
소스
r1(13/05/06)
using System;
using System.IO;
using System.Collections.Generic;
namespace CodeRace
{
class Program
{
public struct pair
{
public string word;
public int count;
}
public static int Compare(pair x, pair y)
{
return x.word.CompareTo(y.word);
}
static void Main(string[] args)
{
List<pair> p = new List<pair>();
pair temp;
string[] s;
string line;
StreamReader sr = new StreamReader(@"C:\test.txt");
while ((line = sr.ReadLine()) != null)
{
s = line.Split(' ');
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < p.Count+1; j++)
{
if (j == p.Count)
{
temp.word = s[i];
temp.count = 1;
p.Add(temp);
break;
}
if (p[j].word == s[i])
{
temp.word = p[j].word;
temp.count = p[j].count + 1;
p[j] = temp;
break;
}
}
}
}
p.Sort(Compare);
for (int i = 0; i < p.Count; i++)
{
if (p[i].word == null) break;
Console.Write(p[i].word+" "+p[i].count+"\n");
}
Console.Read();
}
}
}
r0(13/05/06)
정모/2013.5.6/CodeRace#s-2.2