找出一段英文文本中出现次数最多的10个单词


10年前,中本聪在第一个区块里写了那句著名的话"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks.(2009 年 1 月 3 日,财政大臣正处于实施第二轮银行紧急援助的边缘)",用这句话的出处,<泰晤士报>头版那篇报道的全文为例.

关于这句话

比特币十周年:创世块隐藏了什么秘密?

<泰晤士报>全文

以及这个神奇的网站


全文如下:

Chancellor Alistair Darling on brink of second bailout for banks


Francis Elliott, Deputy Political Editor, and Gary Duncan, Economics Editor

Billions may be needed as lending squeeze tightens

Alistair Darling has been forced to consider a second bailout for banks as the lending drought worsens.

The Chancellor will decide within weeks whether to pump billions more into the economy as evidence mounts that the £37 billion part-nationalisation last year has failed to keep credit flowing. Options include cash injections, offering banks cheaper state guarantees to raise money privately or buying up “toxic assets”, The Times has learnt.

The Bank of England revealed yesterday that, despite intense pressure, the banks curbed lending in the final quarter of last year and plan even tighter restrictions in the coming months. Its findings will alarm the Treasury.

The Bank is expected to take yet more aggressive action this week by cutting the base rate from its current level of 2 per cent. Doing so would reduce the cost of borrowing but have little effect on the availability of loans.

Under one option, a “bad bank” would be created to dispose of bad debts. The Treasury would take bad loans off the hands of troubled banks, perhaps swapping them for government bonds. The toxic assets, blamed for poisoning the financial system, would be parked in a state vehicle or “bad bank” that would manage them and attempt to dispose of them while “detoxifying” the main-stream banking system.

The idea would mirror the initial proposal by Henry Paulson, the US Treasury Secretary, to underpin the American banking system by buying up toxic assets. The idea was abandoned, ironically, when Mr Paulson decided to follow Britain’s plan of injecting cash directly into troubled banks.

Mr Darling, Gordon Brown and Lord Mandelson, the Business Secretary, are expected to take the final decision on what extra help to give the banks by the end of the month.

The banks have taken much of the heat for the economy’s woes. But ministers are said increasingly to accept that attacking the banks will not by itself transform a situation that is jeopardising Britain’s economic prospects.

Insiders point out that Mr Darling’s criticism of mortgage lenders has softened in recent weeks.

After the Bank of England’s radical cuts in interest rates over the past two months, the focus at the Treasury has shifted away from mortgage lending to the pressure being put on businesses by the scarcity of loans, which is emerging as the bigger economic danger.

Richard Lambert, the Director-General of the CBI, said yesterday: “The Government is going to have to do more to restore credit flows across the economy.”

He said that the car industry was especially vulnerable: “Without access to credit or loan guarantees on commercial terms, this vital part of the economy will incur lasting damage.”

The scale of the lending drought was highlighted as separate Bank figures showed that the number of new home loans approved plunged to a record low in November. Only 27,000 mortgages for house purchase were approved by banks and building societies, down from a revised 31,000 in October. It is the lowest level since the Bank began collecting data in 1999. The Bank’s quarterly credit conditions survey showed that banks restricted access to loans of all kinds by companies and consumers in the past quarter, and that they plan to tighten the screws more in this quarter.

Halifax reported that the price of the average house fell by more than £100 a day last year. Its quarterly figures showed that the average house ended the year down in price by £37,178, or 16.2 per cent.

PRESSING THEIR POINT

“The single most pressing challenge to economic policy is to get the banking system to get lending in any normal sense"Mervyn King, Governor of the Bank of England, Nov 26

“They are close to cutting off their noses to spite their faces” Lord Mandelson, Business Secretary, accuses the banks of being too conservative, Nov 30

“The banks have to understand that we have put substantial sums of public money in to support them. They, in turn, need to play their part” Alistair Darling, Dec 10

“Quite clearly a lot more needs to be done” Alistair Darling, Dec 15


package main

import (
 "fmt"
 "io/ioutil"
 "strings"
)

func main() {

    //假定存储该内容的文件存放于与当前文件同级的content.cs中
 ctx := Ioutil("content.cs")

 m := make(map[string]int)

 rs := strings.Split(ctx, " ")

 //fmt.Println(rs)

 for _, v := range rs {
  m[v] += 1
 }

 //此时m是一个键名为单词,键值为出现次数的map,对其进行排序
 fmt.Printf("共有%d个不同的单词\n",len(m))

 sli1 := make([]string0)
 sli2 := make([]int0)

 for key, val := range m {
  sli1 = append(sli1, key)
  sli2 = append(sli2, val)
 }

 //冒泡排序
 for i := 0; i < len(sli2)-1; i++ {
  for j := i + 1; j < len(sli2); j++ {
   if sli2[i] < sli2[j] {
    sli2[i], sli2[j] = sli2[j], sli2[i]
    sli1[i], sli1[j] = sli1[j], sli1[i]
   }
  }
 }

 fmt.Println("出现最多的10个单词为:", sli1[0:10])
 fmt.Println("出现的次数分别为:", sli2[0:10])

}

func Ioutil(name string) string {
 if contents, err := ioutil.ReadFile(name); err == nil {
  //因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符
  result := strings.Replace(string(contents), "\n"""1)
  return result
 }
 return ""
}

运行结果为:

共有380个不同的单词
出现最多的10个单词为: [the to of in that banks by a and lending]
出现的次数分别为: [49 29 25 14 12 10 10 8 7 6]

当然,还可以将m定义为make(map[[]string]int)来简化部分代码

本文由 mdnice 多平台发布

你可能感兴趣的:(后端)