이름으로 점수 내기

5천개쯤 되는 이름 목록이 있는데, A=1, B=2 이런 식으로 해서 점수를 준다. 그 다음에, 그걸 알파벳 순으로 정렬하여, 그 등수에 따라 가중치를 곱해준다.

그런 다음에 그걸 모두 더한다. 얼마일까?

출처 : http://projecteuler.net/index.php?section=problems&id=22

나는 엑셀 VBA로 풀었다.

Sub text()

Dim i As Integer

For i = 1 To 5200

Worksheets(“Sheet2”).Cells(i, 1) = Worksheets(“Sheet2”).Cells(1, 2 * i – 1)

Next

End Sub

Sub Macro1()



‘ Macro1 Macro



Cells.Replace What:=”A”, Replacement:=”+1″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”B”, Replacement:=”+2″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”C”, Replacement:=”+3″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”D”, Replacement:=”+4″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”E”, Replacement:=”+5″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”F”, Replacement:=”+6″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”G”, Replacement:=”+7″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”H”, Replacement:=”+8″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”I”, Replacement:=”+9″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”J”, Replacement:=”+10″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”K”, Replacement:=”+11″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”L”, Replacement:=”+12″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”M”, Replacement:=”+13″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”N”, Replacement:=”+14″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”O”, Replacement:=”+15″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”P”, Replacement:=”+16″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”Q”, Replacement:=”+17″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”R”, Replacement:=”+18″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”S”, Replacement:=”+19″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”T”, Replacement:=”+20″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”U”, Replacement:=”+21″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”V”, Replacement:=”+22″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”W”, Replacement:=”+23″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”X”, Replacement:=”+24″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”Y”, Replacement:=”+25″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”Z”, Replacement:=”+26″, LookAt:=xlPart, SearchOrder _

:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

End Sub

Sub addition()

Dim i As Integer

For i = 1 To 5163

Worksheets(“sheet1”).Cells(i, 2) = “=” + Worksheets(“sheet1”).Cells(i, 1).Value

Next

End Sub

이걸 다 하고 나면 각 이름들의 점수 값이 계산되어 있다.

이제 정렬시켜주고, 가중치를 곱해주고, 다 더하면 된다.

결국, 삽질. -_-;

아마 펄이나 루비로 풀면 몇줄 안될것 같다.

댓글 남기기

이메일은 공개되지 않습니다.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d 블로거가 이것을 좋아합니다: