CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

google中国编程挑战赛-练习题之一(1000分题)

楼主qwerttyy(今天也要快乐!)(每天回十帖)2005-12-08 13:32:14 在 .NET技术 / C# 提问

全英文滴~看不太懂啊~~~~55555555555555  
   
  Problem   Statement  
        
  When   editing   a   single   line   of   text,   there   are   four   keys   that   can   be   used   to   move   the   cursor:   end,   home,   left-arrow   and   right-arrow.   As   you   would   expect,   left-arrow   and   right-arrow   move   the   cursor   one   character   left   or   one   character   right,   unless   the   cursor   is   at   the   beginning   of   the   line   or   the   end   of   the   line,   respectively,   in   which   case   the   keystrokes   do   nothing   (the   cursor   does   not   wrap   to   the   previous   or   next   line).   The   home   key   moves   the   cursor   to   the   beginning   of   the   line,   and   the   end   key   moves   the   cursor   to   the   end   of   the   line.     You   will   be   given   a   int,   N,   representing   the   number   of   character   in   a   line   of   text.   The   cursor   is   always   between   two   adjacent   characters,   at   the   beginning   of   the   line,   or   at   the   end   of   the   line.   It   starts   before   the   first   character,   at   position   0.   The   position   after   the   last   character   on   the   line   is   position   N.   You   should   simulate   a   series   of   keystrokes   and   return   the   final   position   of   the   cursor.   You   will   be   given   a   string   where   characters   of   the   string   represent   the   keystrokes   made,   in   order.   'L'   and   'R'   represent   left   and   right,   while   'H'   and   'E'   represent   home   and   end.  
   
  Definition  
        
  Class:  
  CursorPosition  
  Method:  
  getPosition  
  Parameters:  
  string,   int  
  Returns:  
  int  
  Method   signature:  
  int   getPosition(string   keystrokes,   int   N)  
  (be   sure   your   method   is   public)  
        
   
  Constraints  
  -  
  keystrokes   will   be   contain   between   1   and   50   'L',   'R',   'H',   and   'E'   characters,   inclusive.  
  -  
  N   will   be   between   1   and   100,   inclusive.  
   
  Examples  
  0)  
   
        
  "ERLLL"  
  10  
  Returns:   7  
  First,   we   go   to   the   end   of   the   line   at   position   10.   Then,   the   right-arrow   does   nothing   because   we   are   already   at   the   end   of   the   line.   Finally,   three   left-arrows   brings   us   to   position   7.  
  1)  
   
        
  "EHHEEHLLLLRRRRRR"  
  2  
  Returns:   2  
  All   the   right-arrows   at   the   end   ensure   that   we   end   up   at   the   end   of   the   line.  
  2)  
   
        
  "ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"  
  10  
  Returns:   3  
   
  3)  
   
        
  "RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"  
  19  
  Returns:   12  
   
  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. 问题点数:20、回复次数:11Top

1 楼jinjazz(近身剪)回复于 2005-12-08 13:39:49 得分 0

题目都看不懂就不要参和勒Top

2 楼weisunding(鼎鼎)回复于 2005-12-08 13:40:54 得分 0

我得了997分   :)Top

3 楼leonchenjian(小黑)回复于 2005-12-08 13:56:26 得分 0

比较简单的一题,1000分的难道是第三题?Top

4 楼feiyun0112(http://feiyun0112.cnblogs.com/)回复于 2005-12-08 14:19:17 得分 5

假设有一个字符串,长度为N,keystrokes是按的键,用来移动光标  
   
   
  要得到光标最后在哪个位置Top

5 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-09 08:50:43 得分 0

weisunding(鼎鼎)  
   
  你牛啊。  
   
  有题目和你做的答题吗?发上来看看吧。Top

6 楼thunderclap(认识事物都有两面性)回复于 2005-12-09 10:14:20 得分 0

强烈要求weisunding(鼎鼎)发代码。Top

7 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-09 13:23:22 得分 0

得分:878.6  
   
  using   System;  
   
  public   class   CursorPosition  
  {  
  public   int   getPosition(string   keystrokes,   int   N)  
  {  
  int   iPos   =   0;  
  char[]   cArray   =   keystrokes.ToCharArray();  
   
  for   (int   i   =   0;   i   <   keystrokes.Length;   i++)  
  {  
  switch   (cArray[i])  
  {  
  case   'E':  
  iPos   =   N;  
  break;  
  case   'H':  
  iPos   =   0;  
  break;  
  case   'L':  
  iPos--;  
  break;  
  case   'R':  
  iPos++;  
  break;  
  }  
  if   (iPos   >   N)   iPos   =   N;  
  else   if   (iPos   <   0)   iPos   =   0;  
  }  
  return   iPos;  
  }  
  }  
   
  Top

8 楼fokker(独孤龙)回复于 2005-12-09 15:01:05 得分 15

using   System;  
  using   System.Collections;  
  public   class   CursorPosition  
  {  
  public   int   getPosition(string   keystrokes,   int   N)  
  {  
  Stack   st   =   new   Stack();  
  int   iPos   =   1;  
  for(   int   i=keystrokes.Length-1;   i>=0;   i--   )  
  {  
  if(   keystrokes[i]   !=   'E'   &&   keystrokes[i]   !=   'H'   )    
  {  
  st.Push(   keystrokes[i]   );  
  }  
  else  
  {  
  if(   keystrokes[i]   ==   'E'   )   iPos   =   N;  
  break;  
  }  
  }  
  while(   st.Count   >   0   )  
  {  
  char   c   =   (char)st.Pop();  
  iPos   =   addPos(   iPos,   c,   N   );  
  }  
  return   iPos;  
  }  
   
  private   int   addPos(   int   iPos,   char   cOp,   int   N   )  
  {  
  if(   cOp   ==   'L'   )  
  {  
  if(   iPos   ==   1   )   return   1;  
  iPos--;  
  }  
  else  
  {  
  if(   iPos   ==   N   )   return   N;  
  iPos++;  
  }  
  return   iPos;  
  }  
   
  }Top

9 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-10 08:55:15 得分 0

upTop

10 楼sarrow(阿尔萨斯)回复于 2005-12-10 09:23:27 得分 0

看不懂。Top

11 楼sanjie88(菜鸟依旧,谁动了我的毛片)回复于 2005-12-10 13:34:04 得分 0

题目好像是从网页上拉下来的,Top

相关问题

  • google中国编程挑战赛-练习题之二(500分题)
  • google中国编程挑战赛-练习题之三(250分题)
  • google编程挑战赛试题
  • 参加Google中国编程挑战赛,赢笔记本电脑
  • 求解google编程挑战赛试题的高效算法
  • 总结一下Google编程挑战赛吧.
  • Google编程中国挑战赛第一轮Room18
  • 到底谁是google中国编程挑战赛第一名???
  • Java 网络编程---SL275练习题疑惑
  • 请问谁能弄到《java编程思想》的书后练习题答案?

关键词

  • ipos
  • keystrokes
  • cursor
  • arrow
  • character
  • moves
  • left
  • line
  • st
  • beginning

得分解答快速导航

  • 帖主:qwerttyy
  • feiyun0112
  • fokker

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo