|
答案是
共5163个单词
总分 871198282
以下代码,分别使用了网站的两个函数:
GetDataN http://www.fcode.cn/code_gen-34-1.html
HeapSort http://www.fcode.cn/code_prof-2-1.html
[Fortran] 纯文本查看 复制代码 003 | Integer , parameter :: LEN_ALL = 50000 |
004 | Integer , parameter :: LEN_ONE = 16 |
005 | Character ( Len = LEN_ALL ) :: cStrAll |
006 | Character ( Len = LEN_ONE ) , allocatable :: cStrSplit ( : ) |
007 | integer :: n , sum , score |
009 | Open ( 12 , File = "names.txt" ) |
010 | Read ( 12 , '(a50000)' ) cStrAll |
012 | n = GetDataN ( cStrAll ) |
013 | write ( * , '(a,i0,a)' ) '共' , n , '个单词' |
014 | Allocate ( cStrSplit ( n ) ) |
015 | read ( cStrAll , * ) cStrSplit |
016 | call HeapSort ( cStrSplit , comp_f ) |
019 | sum = sum + i * GetStringScore ( Trim ( cStrSplit ( i ) ) ) |
021 | write ( * , * ) '总分' , sum |
022 | Deallocate ( cStrSplit ) |
026 | Integer Function GetStringScore ( c ) |
027 | Character ( Len = * ) :: c |
030 | Do i = 1 , Len_Trim ( c ) |
031 | GetStringScore = GetStringScore + ( ichar ( c ( i : i ) ) - ichar ( 'A' ) + 1 ) |
033 | End Function GetStringScore |
035 | Integer Function GetDataN ( cStr ) |
036 | Character ( Len = * ) , Intent ( IN ) :: cStr |
038 | Logical :: bIsSeparator , bIsQuote |
040 | bIsSeparator = .TRUE. |
042 | Do i = 1 , Len_Trim ( cStr ) |
043 | Select Case ( cStr ( i : i ) ) |
045 | If ( .Not. bIsQuote ) GetDataN = GetDataN + 1 |
046 | bIsQuote = .Not. bIsQuote |
047 | bIsSeparator = .FALSE. |
048 | Case ( " " , "," , char ( 9 ) ) |
049 | If ( .Not. bIsQuote ) then |
050 | bIsSeparator = .TRUE. |
053 | If ( bIsSeparator ) then |
054 | GetDataN = GetDataN + 1 |
056 | bIsSeparator = .FALSE. |
059 | End Function GetDataN |
061 | Subroutine HeapSort ( stD , comp_f ) |
062 | Character ( Len = * ) , Intent ( INOUT ) :: stD ( : ) |
063 | Real , External :: comp_f |
065 | Character ( Len = LEN_ONE ) :: stTemp |
086 | If ( ( j < ir ) ) then |
087 | If ( comp_f ( stD ( j ) , std ( j +1 ) ) > 0.0 ) then |
091 | If ( comp_f ( stTemp , stD ( j ) ) > 0.0 ) then |
101 | End Subroutine HeapSort |
103 | Real Function comp_f ( st 1 , st 2 ) |
104 | Character ( Len = * ) , Intent ( IN ) :: st 1 , st 2 |
105 | if ( Trim ( st 1 ) > Trim ( st 2 ) ) then |
112 | end program www_fcode_cn |
|
|