找出一段英文文本中出现次数最多的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 多平台发布

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define MAX_WORD_LEN 100 // 最大单词长度 #define TOP_N 10 // 前N个出现次数最多的单词 // 单词结构体 typedef struct { char word[MAX_WORD_LEN]; // 单词 int count; // 出现次数 } Word; // 比较函数,用于qsort排序 int cmp(const void *a, const void *b) { return ((Word *)b)->count - ((Word *)a)->count;} int main() { char filename[100]; // 文件名 printf("请输入文件名:"); scanf("%s", filename); FILE *fp = fopen(filename, "r"); // 打开文件 if (fp == NULL) { printf("文件打开失败!\n"); return 0; } Word *words = (Word *)malloc(sizeof(Word) * 1000); // 动态分配内存 int wordCount = 0; // 单词数量 char word[MAX_WORD_LEN]; // 临时存储单词 int len = 0; // 单词长度 char c; // 临时存储字符 while ((c = fgetc(fp)) != EOF) { // 逐个字符读取文件 if (isalpha(c)) { // 如果是字母 if (len < MAX_WORD_LEN - 1) { // 如果单词长度未超过最大长度 word[len++] = tolower(c); // 转换为小写字母并存储 } } else if (len > 0) { // 如果不是字母且单词长度大于0 word[len] = '\0'; // 添加字符串结束符 int i; for (i = 0; i < wordCount; i++) { // 查单词是否已存在 if (strcmp(words[i].word, word) == 0) { // 如果已存在 words[i].count++; // 出现次数加1 break; } } if (i == wordCount) { // 如果不存在 strcpy(words[wordCount].word, word); // 存储单词 words[wordCount].count = 1; // 出现次数为1 wordCount++; // 单词数量加1 } len = 0; // 重置单词长度 } } fclose(fp); // 关闭文件 qsort(words, wordCount, sizeof(Word), cmp); // 按出现次数排序 printf("出现次数前%d的单词:\n", TOP_N); int i; for (i = 0; i < TOP_N && i < wordCount; i++) { // 输前N个单词 printf("%s\t%d\n", words[i].word, words[i].count); } free(words); // 释放内存 return 0; } ``` --相关问题--: 1. 如何统计一个文本文件出现次数最多的前十个汉字

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值