![]() |
|
|||||||
| 論壇說明 | 標記討論區已讀 |
|
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
![]() |
|
|
主題工具 | 顯示模式 |
|
|
|
|
#1 (permalink) |
|
註冊會員
![]() |
語法:
import java.util.Arrays;
public class Slime {
public static void main(String[] args) {
String src = "WASHINGTON - Gerald R. Ford was a man of limited ambition who, through bizarre circumstances never before experienced by the country, achieved an office that others win through the greatest determination and calculation. The nation's 38th president, Ford wanted only to become speaker of the House. History had another place for him. ADVERTISEMENT Ford was comfortable in the House, representing a Michigan congressional district for 25 years, rising to Republican leader and working toward his dream of one day running the chamber, when President Nixon called.He needed a new vice president; scandal had chased Spiro Agnew from the office.Ford wasn't Nixon's first choice, but the president agreed that the amiable Republican would be the easiest to win confirmation by both houses of Congress. So it went, and Ford became vice president in December 1973.Yet eight months later, the scenario got even stranger.";
String[] array = src.replaceAll("\\W", " ").split("\\s+");
Arrays.sort(array);
int n = 1;
for (int i = 0; i < array.length - 1; i++) {
if (array[i].equals(array[i + 1])) {
n++;
} else {
System.out.println(n + " " + array[i]);
n = 1;
}
}
}
}
語法:
頻率 字 1 1973 1 25 1 38th 1 ADVERTISEMENT 1 Agnew 1 Congress 1 December 5 Ford 1 Gerald 1 He 1 History 2 House 1 Michigan 2 Nixon 1 President 1 R 2 Republican 1 So 1 Spiro 1 The 1 WASHINGTON 1 Yet 3 a 1 achieved 1 agreed 1 ambition 1 amiable 1 an 3 and 1 another 1 be 1 became 1 become 1 before 1 bizarre 1 both 1 but 2 by 1 calculation 1 called 1 chamber 1 chased 1 choice 1 circumstances 1 comfortable 1 confirmation 1 congressional 1 country 1 day 1 determination 1 district 1 dream 1 easiest 1 eight 1 even 1 experienced 1 first 2 for 1 from 1 got 1 greatest 2 had 1 him 1 his 1 houses 2 in 1 it 1 later 1 leader 1 limited 1 man 1 months 1 nation 1 needed 1 never 1 new 4 of 2 office 1 one 1 only 1 others 1 place 4 president 1 representing 1 rising 1 running 2 s 1 scandal 1 scenario 1 speaker 1 stranger 1 t 2 that 10 the 2 through 3 to 1 toward 2 vice 1 wanted 2 was 1 wasn 1 went 1 when 1 who 2 win 1 working 1 would |
|
|
送花文章: 623,
|
|
向 snoopy 送花的會員:
|
|
|
#2 (permalink) | |
|
長老會員
![]() |
引用:
要排序啦 XD >__< 別和阿鳥一樣偷懶咩 XD |
|
|
__________________ 思考,正是從一個錯誤,跳進另外一個錯誤。 |
||
|
|
送花文章: 5387,
|
|
|
#3 (permalink) | |
|
協調管理員
![]() |
那有,我明明就可以
引用:
|
|
|
__________________ |
||
|
|
送花文章: 11706,
|
|
|
#4 (permalink) | |
|
長老會員
![]() |
引用:
仔細看,不太正確,讓空白的地方沒有空白,不該有逗點的地方卻有逗點 ^_^ 泥的答案在偶的機子上跑出來的結果... ==== Gale,Dorothy OFFICE_02 TEL_NUM_02 Hancock,John OFFICE_03 TEL_NUM_03 W.,Adrian Jones OFFICE_01 ==== == 這二大題難就難在輸出格式,如果大家都不照格式去寫,那這就失去它的意義 總之,該排序的地方就要排序,格式要注意的地方就得注意,不然偶就白問了 = =a |
|
|
|
送花文章: 5387,
|