華為機試題 找一句話中最長的單詞

2021-06-20 21:27:05 字數 739 閱讀 5087

一、問題描述

功能描述:鍵盤輸入一句話

輸出一句話中最常的單詞,如果最長的出現多次,返回第乙個。

這句話只包含數字字母和標點。

輸入:a aa,cat tiger.123dd 

輸出: tiger

要求實現方法:

public string getlongstring(string data)

二、演算法分析

1. 關鍵問題,如何用正規表示式來匹配標點

2. 如何判斷乙個子字串裡面都是字元。

其實這兩個問題歸於一點就是正規表示式使用。

特別要注意,正規表示式要匹配英文句號一定要加轉義符號。

三、演算法

public string getlongstring1(string test)

}return result;

}

測試類:

package com.albertshao.csi.interview;

/** * @author albertshao

* */

public class main9

public string getlongstring1(string test)

}return result;

}}

執行結果:

tiger

一句話的perl

zcat perl e while 1.hello world 還是從最經典的 hello,world 開始.perl e print hello,world n hello,world 完全不出意料,他沒有任何歧異的終於我們願意的輸出了 hello,world 自然得就像我麼用echo或 prin...

一句話的經典

老外的 的確更精練管用!2.比如 交換word,longint的位元組順序,以便檔案的讀寫 直接用swap支援word longint用 swap bytes for big to littleendian conversion function swap32 along longint longi...

Debian的一句話問答

debian的一句話問答 2006 03 15 在本一句話問答中,一般來說 開頭的命令表示需要root許可權,開頭的表示普通使用者許可權即可 debian的發音 debian is pronounced deb ee en 類似於帶賓 參考以下 發音的英文檔案 頁面中subscribe unsubs...