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;
          }  回復  更多評論
            

          主站蜘蛛池模板: 亳州市| 平江县| 扬州市| 祥云县| 青浦区| 朝阳县| 琼结县| 清徐县| 宜都市| 阿瓦提县| 醴陵市| 陕西省| 黔西| 通道| 通化市| 荣成市| 邵阳县| 襄城县| 嵊泗县| 新民市| 满城县| 谢通门县| 尉犁县| 叙永县| 沙洋县| 乌海市| 介休市| 托里县| 永定县| 宝坻区| 凤凰县| 沅江市| 阿巴嘎旗| 澎湖县| 潜江市| 江川县| 宁化县| 大渡口区| 宽甸| 视频| 怀来县|