CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  新手乐园

新人50分求一简单程序

楼主yanleixinleo(眼泪心)2005-04-01 12:37:21 在 C/C++ / 新手乐园 提问

偶初学这个~老师布置的一道题~思考了好久都不得要领~请各位高手指教!  
  Time   limit:   1   Seconds       Memory   limit:   32768K        
  Total   Submit:   5552       Accepted   Submit:   1081        
   
  --------------------------------------------------------------------------------  
   
  If   you   ever   tried   to   read   a   html   document   on   a   Macintosh,   you   know   how   hard   it   is   if   no   Netscape   is   installed.    
  Now,   who   can   forget   to   install   a   HTML   browser?   This   is   very   easy   because   most   of   the   times   you   don't   need   one   on   a   MAC   because   there   is   a   Acrobate   Reader   which   is   native   to   MAC.   But   if   you   ever   need   one,   what   do   you   do?    
  Your   task   is   to   write   a   small   html-browser.   It   should   only   display   the   content   of   the   input-file   and   knows   only   the   html   commands   (tags)   <br>   which   is   a   linebreak   and   <hr>   which   is   a   horizontal   ruler.   Then   you   should   treat   all   tabulators,   spaces   and   newlines   as   one   space   and   display   the   resulting   text   with   no   more   than   80   characters   on   a   line.    
   
  Input   Specification  
  The   input   consists   of   a   text   you   should   display.   This   text   consists   of   words   and   HTML   tags   separated   by   one   or   more   spaces,   tabulators   or   newlines.    
  A   word   is   a   sequence   of   letters,   numbers   and   punctuation.   For   example,   "abc,123"   is   one   word,   but   "abc,   123"   are   two   words,   namely   "abc,"   and   "123".   A   word   is   always   shorter   than   81   characters   and   does   not   contain   any   '<'   or   '>'.   All   HTML   tags   are   either   <br>   or   <hr>.    
   
  Output   Specification  
  You   should   display   the   the   resulting   text   using   this   rules:    
  If   you   read   a   word   in   the   input   and   the   resulting   line   does   not   get   longer   than   80   chars,   print   it,   else   print   it   on   a   new   line.    
  If   you   read   a   <br>   in   the   input,   start   a   new   line.    
  If   you   read   a   <hr>   in   the   input,   start   a   new   line   unless   you   already   are   at   the   beginning   of   a   line,   display   80   characters   of   '-'   and   start   a   new   line   (again).    
  The   last   line   is   ended   by   a   newline   character.    
  Sample   Input  
  Hallo,   dies   ist   eine    
  ziemlich   lange   Zeile,   die   in   Html  
  aber   nicht   umgebrochen   wird.  
  <br>  
  Zwei   <br>   <br>   produzieren   zwei   Newlines.    
  Es   gibt   auch   noch   das   tag   <hr>   was   einen   Trenner   darstellt.  
  Zwei   <hr>   <hr>   produzieren   zwei   Horizontal   Rulers.  
  Achtung               mehrere   Leerzeichen   irritieren  
   
  Html   genauso   wenig   wie  
   
   
  mehrere   Leerzeilen.  
   
  Sample   Output  
  Hallo,   dies   ist   eine   ziemlich   lange   Zeile,   die   in   Html   aber   nicht   umgebrochen  
  wird.  
  Zwei  
   
  produzieren   zwei   Newlines.   Es   gibt   auch   noch   das   tag  
  --------------------------------------------------------------------------------  
  was   einen   Trenner   darstellt.   Zwei  
  --------------------------------------------------------------------------------  
  --------------------------------------------------------------------------------  
  produzieren   zwei   Horizontal   Rulers.   Achtung   mehrere   Leerzeichen   irritieren   Html  
  genauso   wenig   wie   mehrere   Leerzeilen.  
  问题点数:50、回复次数:11Top

1 楼yanleixinleo(眼泪心)回复于 2005-04-01 12:46:55 得分 0

忘了说是在C++环境下~3QTop

2 楼pcboyxhy(-273.15℃)回复于 2005-04-01 12:48:09 得分 0

#include   <iostream>    
  #include   <string>    
  #include   <fstream>    
  using   namespace   std;    
  string   word;    
  int   word_l,poi;    
  int   main()    
  {  
  poi=0;word="";    
  while(cin>>word)    
  {word_l=word.length();    
  if(word=="<br>"){cout<<endl;poi=0;}    
  if(word=="<hr>")    
  {if(poi!=0)cout<<endl;    
  for(int   i=1;i<=80;i++)cout<<"-";    
  cout<<endl;    
  poi=0;    
  }    
  if(word!="<br>"   &&   word!="<hr>")    
  {if(poi==0){cout<<word;poi=word_l;}    
  else    
  if(poi>0   &&   poi+word_l+1<=80){cout<<"   "<<word;poi+=word_l+1;}    
  else    
  if(poi>0   &&   poi+word_l+1>   80){cout<<endl<<word;poi=word_l;}    
  }    
  }    
  cout<<endl;    
  }  
   
  我搜来的  
  你试试看Top

3 楼pcboyxhy(-273.15℃)回复于 2005-04-01 12:49:19 得分 0

#include   <iostream.h>    
  #include   <stdio.h>    
  #include   <string.h>    
   
  int   line;    
  char   data[100];    
   
  int   main   ()   {    
  int   br,hr,len,i;    
   
  line=0;    
  while   (scanf("%s",data)>0)   {    
  br=strcmp(data,"<br>");    
  hr=strcmp(data,"<hr>");    
  if   (br==0)   {    
  cout<<endl;    
  line=0;    
  }    
  if   (hr==0)   {    
  if   (line>0)    
  cout<<endl;    
  for   (i=0;i<80;i++)    
  cout<<'-';    
  cout<<endl;    
  line=0;    
  }    
  if   (br!=0   &&   hr!=0)   {    
  len=strlen(data);    
  if   (line==0)   {    
  cout<<data;    
  line=len;    
  }    
  else   {    
  if   ((line+1+len)<=80)   {    
  cout<<'   '<<data;    
  line+=len+1;    
  }    
  else   {    
  cout<<endl<<data;    
  line=len;    
  }    
  }    
  }    
  }    
  cout<<endl;    
   
  return   0;    
  }  
   
   
   
  这个也是搜来的  
  看看吧Top

4 楼yanleixinleo(眼泪心)回复于 2005-04-01 13:00:08 得分 0

和正确的输出结果不一样的啊~我在看看吧~Top

5 楼pcboyxhy(-273.15℃)回复于 2005-04-01 13:03:51 得分 0

这两个都是  
   
  ZJU1099的Top

6 楼yanleixinleo(眼泪心)回复于 2005-04-01 17:05:38 得分 0

怎么没有高手来带新人一把呀~Top

7 楼wasoxi(我就是(没意思~~~))回复于 2005-04-01 17:13:02 得分 0

看到那长长的E文我怕了...................Top

8 楼pcboyxhy(-273.15℃)回复于 2005-04-01 17:15:45 得分 50

#include<iostream>    
  #include<string>    
  using   namespace   std;    
   
  int   main()    
  {    
          string   s,   s1;    
          int   num   =   0;    
          while(   cin   >>   s   )    
          {    
                if(   s[0]   ==   '<'   )    
                  {    
                                  if(   num   !=   0   )    
                                  for(   int   i   =   0;   i   <   s1.length()-1;   i++   )cout   <<   s1[i];    
                                  s1.erase();//s1   =   "";    
                                  if(   s[1]   ==   'b'   )    
                                  {    
                                          cout   <<   endl;                      
                                  }    
                                  else    
                                  {    
                                          if(   num   !=   0   )    
                                          cout   <<   endl;    
                                          for(   int   i   =   0;   i   <   80;   i++   )    
                                          cout   <<   "-";    
                                          cout   <<   endl;    
                                  }          
                                  num   =   0;    
                  }    
                  else    
                  {    
                                  s1   +=   s;    
                                  s1   +=   "   ";    
                                  num   +=   s.length();    
                                  num   ++;    
                                  if(   num   ==   80   )    
                                  {    
                                                                  for(   int   i   =   0;   i   <   79;   i++   )    
                                                                  {    
                                                                                      cout   <<   s1[i];          
                                                                  }          
                                                                  cout   <<   endl;    
                                                                  s1.erase(   );    
                                                                    num   -=   80;    
                                  }    
                                  else   if(   num   >   80   )    
                                  {    
                                          for(   int   i   =   0;   i   <   num   -   s.length()   -   2   ;   i++   )    
                                          cout   <<   s1[i];    
                                          cout   <<   endl;    
                                          s1.erase(   0,   num   -   s.length()-1   );    
                                          num   =   s.length()   +   1;    
                                           
                                  }          
                                   
                  }          
   
          }    
          if(   num   !=   80   )   for(   int   i   =   0;   i   <   s1.length()-1;   i++   )cout   <<   s1[i];    
    cout<<endl;                        
   
  }  
   
   
  这个AC了  
  我测试过Top

9 楼yanleixinleo(眼泪心)回复于 2005-04-01 17:42:34 得分 0

OK  
  3Q~给分~结帖Top

10 楼yanleixinleo(眼泪心)回复于 2005-04-01 17:44:18 得分 0

:)Top

11 楼yanleixinleo(眼泪心)回复于 2005-04-01 17:48:50 得分 0

怎么给???Top

相关问题

  • 一个简单的程序!
  • 求一简单程序?
  • 一个简单的程序。。。
  • 求一简单程序....
  • 求一段简单程序
  • 一个简单程序。
  • 一个简单的程序
  • 求助一简单程序
  • 一段简单COM程序的问题
  • 一个简单的程序!请做

关键词

  • word
  • tag
  • start
  • html
  • zwei
  • mehrere
  • produzieren
  • newlines
  • horizontal rulers
  • line

得分解答快速导航

  • 帖主:yanleixinleo
  • pcboyxhy

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

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