typoglycemia

单词里面字母乱序不影响阅读的现象,学名叫做Typoglycemia :
http://en.wikipedia.org/wiki/Typoglycemia


package test;

import java.util.ArrayList;
import java.util.Collections;

public class Test001 {

private static String typoglycemia(String s){
if(s.length()<3){
return s;
}
ArrayList al = new ArrayList();
for(int i=1; i<s.length()-1; i++){
al.add(s.charAt(i));
}
Collections.shuffle(al);
StringBuffer sb = new StringBuffer();
sb.append(s.charAt(0));
for(int i=1; i<s.length()-1; i++){
sb.append( al.get(i-1) );
}
sb.append(s.charAt(s.length()-1));
return sb.toString();
}

private static void test01(){
String[] ss = {
"This",
"tutorial",
"is",
"designed",
"for",
"two",
"groups",
"of",
"people",
"The",
"first",
"includes",
"those",
"who",
"are",
"new",
"to",
"Eclipse",
"and",
"want",
"to",
"understand",
"it's",
"basic",
"functionality",
"Although",
"we",
"use",
"a",
"Java",
"project",
"as",
"our",
"example,",
"this",
"tutorial",
"involves",
"no",
"programming",
"and",
"is",
"designed",
"so",
"that",
"the",
"content",
"is",
"relevant",
"to",
"any",
"application",
"that",
"uses",
"the",
"Eclipse",
"workbench"
};
for(int i=0; i<ss.length; i++){
//System.out.println( s );
System.out.print( typoglycemia(ss[i]) );
System.out.print( " " );
}
}

private static void test02(){
String s = "Typoglycemia is a neologism given to a purported recent discovery about the cognitive processes behind " +
"reading written text. The word does not refer to any actual medical condition related to hypoglycemia. The " +
"word appears to be a portmanteau of \"typo\", as in typographical error, and \"hypoglycemia\". It is an urban " +
"legend/Internet meme that appears to have an element of truth to it.\r\n\r\n" +
"The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the " +
"meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the " +
"necessary letters are present, and the first and last letters remain the same, readers appear to have little " +
"trouble reading the text.";
StringBuffer sb = new StringBuffer();
int begin = 0;
int end = 0;
boolean isBegin = false;
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
// System.out.println( "isBegin:" + isBegin );
// System.out.println( "c:" + c );
if(isBegin == false){
if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
isBegin = true;
begin = i;
} else {
sb.append(c);
}
}
else{
if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
} else{
isBegin = false;
end = i;
// System.out.println( "begin:" + begin );
// System.out.println( "end:" + end );
String s1 = s.substring(begin, end);
sb.append(typoglycemia(s1));
sb.append(c);
}

}
// System.out.println( "isBegin:" + isBegin );

}
System.out.println( s );
System.out.println( sb.toString() );
}


/**
* @param args
*/
public static void main(String[] args) {
test02();
}

}




运行结果:
原文:
Typoglycemia is a neologism given to a purported recent discovery about the cognitive processes behind reading written text. The word does not refer to any actual medical condition related to hypoglycemia. The word appears to be a portmanteau of "typo", as in typographical error, and "hypoglycemia". It is an urban legend/Internet meme that appears to have an element of truth to it.

The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the necessary letters are present, and the first and last letters remain the same, readers appear to have little trouble reading the text.

----------------------------
打乱后:
Toeiyyplmcga is a nlsoiogem gievn to a pruroeptd rneect deicvsroy about the cvtgiinoe pcseoress bnihed rianedg wteitrn txet. The word deos not refer to any aauctl micaedl cntodoiin rtlaeed to hymicyoplega. The wrod aepraps to be a potramnaetu of "typo", as in tpgiycphoaarl error, and "hepiymoylgca". It is an urabn leengd/Ieetnnrt mmee taht arpeaps to have an enelmet of tturh to it.

The leegnd, ptrapogead by email and msgaese brados, ptlrouedpry dtartmeonses taht rdreaes can udnetsnrad the manenig of wrdos in a snceetne eevn wehn the ineitorr leterts of each wrod are sleramcbd. As lnog as all the ncseerasy lttrees are prsenet, and the frist and last lrteets rmaein the same, rerdaes apepar to have ltilte tlbuore rnaedig the text.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值