staticvoidinput() { Scannerinput=newScanner(System.in); s1 = input.nextLine(); s2 = input.nextLine(); intlen1= s1.length(); intlen2= s2.length(); // for(int i=0;i<word1.length;i++) System.out.println(word1[i]); } static String process(String A, String B) { String common=""; word1 = A.split(" "); word2 = B.split(" "); intlen1= word1.length; intlen2= word2.length; for(int i=0;i<len1;i++) { for(int j=0;j<len2;j++) { intpos= word2[j].indexOf(word1[i]); if(pos!=-1) { word2[j] = word2[j].substring(0,pos) + word2[j].substring(pos+word1[i].length()); common = common + word1[i]; break; } } } return common; } static String declan(String c1, String c2) { String ans=""; intlen1= c1.length(); for(int i=0;i<len1;i++) { Stringtmp= c1.substring(i, i+1); intpos= c2.indexOf(tmp); if(pos==-1) continue; ans = ans + tmp; c2 = c2.substring(pos+1); } return (ans=="")?("NONE"):(ans); } publicstaticvoidmain(String[] args) { for(int i=0;i<5;i++) { System.out.println("Please enter No."+(i+1)+" line of the input data:"); input(); Stringcommon1= process(s1,s2); Stringcommon2= process(s2,s1); System.out.println("The answer to No."+(i+1)+"line is:"); System.out.println(declan(common1,common2)); // System.out.println(common1); // System.out.println(common2); } System.out.println("All output done..."); System.out.println("Thanks for your testing"); // return; } } /* The quick brown fox did jump over a log The brown rabbit quickly did outjump the fox How much wood would a woodchuck chuck if a woodchuck could chuck wood He would chuck as much wood as a woodchuck could I scream you scream we all scream for ice cream He screams she screams they all scream for a creamery A skunk sat on a stump and thunk the stump stunk but the stump thunk the skunk stunk I have got a date at a quarter to eight I will see you at the gate so do not be late abc defgh ijkl mnopq rstuv wxyz ab cdefgh ijklmn opq rst uv w xy z */
Nothing… The problem is pretty easy, however it troubled me for a quite long time. Just follow the instruction of the problem and simulate the whole process by coding.
C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作。vector封装数组,list封装了链表,map和set封装了二叉树等,在封装这些数据结构的时候,STL按照程序员的使用习惯,以成员函数方式提供的常用操作,如:插入、排序、删除、查找等。让用户在STL使用过程中,并不会感到陌生。
voiddfs(int x,int a,int b,int c)// num from trans end { if(x==1) { printf("move from %d to %d\n",a,c); ans++; return; } dfs(x-1,a,c,b); printf("move from %d to %d\n",a,c); ans++; dfs(x-1,b,a,c); }