emu in blogjava

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            171 隨筆 :: 103 文章 :: 1052 評論 :: 2 Trackbacks
          ReverseSubstring
          You are given a String input. You are to find the longest substring of 
          input such that the reversal of the substring is also a substring of 
          input. In case of a tie, return the string that occurs earliest in 
          input. 
          Definition 
          給你一個字符串,你再生成一個顛倒的字符串,從原串中找出任意子串能同時存在顛倒的字符串中, 
          求出最長子串 
          Class: 
          ReverseSubstring 
          Method: 
          findReversed 
          Parameters: 
          String 
          Returns: 
          String 
          Method signature: 
          String findReversed(String input) 
          (be sure your method is public) 
          類ReverseSubstring方法  public String findReversed(String input) 


          Notes 

          The substring and its reversal may overlap partially or completely. 

          The entire original string is itself a valid substring (see example 4). 
          Constraints 

          input will contain between 1 and 50 characters, inclusive. 

          Each character of input will be an uppercase letter ('A'-'Z'). 
          Examples 
          0) 


          "XBCDEFYWFEDCBZ" 
          Returns: "BCDEF" 
          We see that the reverse of BCDEF is FEDCB, which appears later in the 
          string. 
          顛倒的字符串為"ZBCDEFWYFEDCBX",原串中BCDEF也是顛倒的字符串的子串,并且為最長的 
          1) 


          "XYZ" 
          Returns: "X" 
          The best we can do is find a one character substring, so we implement 
          the tie-breaker rule of taking the earliest one first. 
          2) 


          "ABCABA" 
          Returns: "ABA" 
          The string ABA is a palindrome (it's its own reversal), so it meets the 
          criteria. 
          3) 


          "FDASJKUREKJFDFASIREYUFDHSAJYIREWQ" 
          Returns: "FDF" 


          4) 


          "ABCDCBA" 
          Returns: "ABCDCBA" 
          Here, the entire string is its own reversal. 
          This problem statement is the exclusive and proprietary property of 
          TopCoder, Inc. Any unauthorized use or reproduction of this information 
          without the prior written consent of TopCoder, Inc. is strictly 
          prohibited. (c)2003, TopCoder, Inc. All rights reserved.
          posted on 2005-12-13 13:35 emu 閱讀(1578) 評論(5)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

          評論

          # re: google中國編程挑戰賽資格賽真題 -- ReverseSubstring 2006-08-28 00:59 bitstream
          我想詢問一下google編程競賽的情況,以前沒參加過,還望不吝賜教。Qualification Round是不是舉行一整天?一共有幾道題目?比賽用的程序現在能否down下來練練手?
          望回復!感謝!  回復  更多評論
            

          # re: google中國編程挑戰賽資格賽真題 -- ReverseSubstring 2006-08-29 01:21 emu
          下個星期的資格賽說明是:
          The Qualification Round will be open from Tuesday, September 5, at 12:00 PM (noon) EDT (GMT/UTC -4) through Wednesday, September 6, at 12:00 PM (noon) EDT (GMT/UTC -4). During this 24-hour period, each competitor must complete one randomly generated problem set. All competitors will receive a score for their performance on that one problem set.

          如果你已經注冊參賽,在確認郵件的 PRACTICING FOR THE EVENT 一段中有關于賽前練手的信息,我收集的題目也可以用來練手。如果你還沒有注冊就抓緊注冊吧,不注冊是不能啟用competition arena來練手的。  回復  更多評論
            

          # re: google中國編程挑戰賽資格賽真題 -- ReverseSubstring 2006-08-29 17:12 bitstream
          謝謝!
          也就是說每人隨機抽一套題做。我剛注冊了,抽空下點題目看看。你這里的題目我基本都有收集,大多數題不難,只是用的時間太長。(有時間我會把我的解答貼到這里,還望多多指教)
          另外,可否就比賽給小弟一些建議?或者談談您參賽的經驗?
          感激不盡!Have a nice day!  回復  更多評論
            

          # re: google中國編程挑戰賽資格賽真題 -- ReverseSubstring 2006-09-04 20:27 小貓魚
          import java.io.BufferedReader;
          import java.io.IOException;
          import java.io.InputStreamReader;
          import java.util.*;


          public class ReverseSubstring {
          private static String original="";
          public static void main(String[] args) throws IOException {
          String s=input();
          String s1=reversed(s);
          System.out.println(findReversed(Reversedsub(s),Reversedsub( s1))+"結果");
          }
          static String findReversed(Hashtable orig,Hashtable reversed){

          Enumeration enum=orig.elements();
          String result=original.substring(0,1);
          while(enum.hasMoreElements()){
          String s=(String)enum.nextElement();

          if( s.equals(reversed.get(s))){
          if(s.length()>=result.length()){
          result=s;
          }

          }
          }

          return result;

          }
          static Hashtable Reversedsub(String s){
          String originals=s;
          Hashtable hash=new Hashtable();
          for(int m=0;m<originals.length();m++){
          for(int i=0;i<originals.length()-m;i++){
          String sub= originals.substring(i,i+m+1);

          hash.put(sub,sub);
          }
          }
          return hash;
          }

          static String reversed(String s){
          int len=0;
          char[] original=s.toCharArray();
          len= original.length;
          char[] rever=new char[len];
          int m=len-1;
          for( int i=0;i<=len-1;i++){
          rever[i]=original[m];
          m--;
          }
          return new String(rever);
          }
          static String input() throws IOException{
          int first=0;
          boolean stop=true;
          while(stop){
          if(first!=0){
          original="輸入出錯請重新輸入";
          }
          else{
          original="請輸入數據";
          }
          System.out.println(original);
          BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
          original=input.readLine();
          if(original.length()==0||original.length()>50){
          original="輸入出錯請重新輸入";
          }
          else{
          stop=false;
          }
          first+=1;
          }
          return original;
          }

          }  回復  更多評論
            

          # re: google中國編程挑戰賽資格賽真題 -- ReverseSubstring 2009-07-11 21:02 Mandy
          @小貓魚
          bool Strstr(const char cStr1[], const char cStr2[], int Start, int Count)
          {
          char *SubString = (char*)malloc(Count + 1);
          memcpy(SubString, cStr2+Start, Count);
          SubString[Count] = '\0';
          char *find = strstr(cStr1, SubString);
          free(SubString);
          return find == NULL?false:true;
          }

          int GetSubString(char cStr[], int iSeatCount)
          {
          int left=0;
          int right=iSeatCount-1;
          int startindex = 0;
          int last = 0;
          int templast = 0;
          char ch='\0';
          char *ReverseSubstring = (char*)malloc(iSeatCount + 1);
          memcpy(ReverseSubstring, cStr, iSeatCount + 1);
          while(left <= right)
          {
          ch = ReverseSubstring[left];
          ReverseSubstring[left] = ReverseSubstring[right];
          ReverseSubstring[right] = ch;
          left++;
          right = iSeatCount-1-left;
          }
          ReverseSubstring[iSeatCount] = '\0';
          for (int i=0; i<iSeatCount; i++)
          {
          templast = 1;
          while (Strstr(ReverseSubstring, cStr, i, templast) && templast <= iSeatCount - i)
          {
          templast++;
          }
          if ((templast - 1) > last)
          {
          startindex = i;
          last = templast - 1;
          }
          }
          printf("The StartPostion is %d and the last number is %d.\n", startindex, last);
          printf("The Max Common String is ");
          for (i=0; i<last; i++)
          {
          printf("%c", *(cStr+startindex+i));
          }
          printf("\n");
          return last;
          }  回復  更多評論
            

          主站蜘蛛池模板: 溧阳市| 贵溪市| 时尚| 云龙县| 霍林郭勒市| 霞浦县| 开化县| 平罗县| 衡山县| 喀喇沁旗| 都匀市| 蛟河市| 苍溪县| 泊头市| 柘城县| 前郭尔| 青州市| 弋阳县| 湘乡市| 仁化县| 衡山县| 金门县| 防城港市| 霍城县| 民勤县| 洪洞县| 广灵县| 棋牌| 曲水县| 将乐县| 安康市| 正阳县| 友谊县| 万山特区| 淅川县| 丹东市| 华蓥市| 马公市| 岳西县| 英山县| 天水市|