付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0
http://acm.hdu.edu.cn/showproblem.php?pid=1088 

这道题 让我对 cin  和 scanf  有更多的了解 刚开始用gets  读入 但是由于不好控制 读入下个单词时 这行是否 会超过80 个字符 包括空格;

而使用 scanf  这个对换行符 处理不是很好 ,于是就用了 cin 很好的以空格和换行符读入单词 ,这个题贡献了很多次 表达错误 ,
#include<iostream>
using namespace std;

# include
<stdio.h>
# include
<stdlib.h>
# include
<string.h>
int main()
{
    
//freopen("myout.txt","w",stdout);
    char str[100],str1[20];
    
int i,j,len,count = 0,flag = 1;//flag 用来防止 两个hr 而出现中间空行的现象
    while (cin>>str)
    
{
        
if (strcmp(str,"")==0)
            
continue;
        len 
= strlen(str);

        
if (strcmp(str,"<br>")==0)
            printf(
"\n"),count =0;
        
else if (strcmp(str,"<hr>")==0)
        
{
            
if (count)printf("\n");
            
for (j = 0;j<80;j++)
                printf(
"-");
            printf(
"\n");
            count 
= 0;
            flag 
= 1;
        }

        
else
        
{
            
if (count + len +1 <= 80//因为要加一个空格
            {
                
if (count )
                    printf(
" "),count ++;
                printf(
"%s",str);
                count 
+= len;
            }

            
else
            
{
                printf(
"\n"),count = len,printf("%s",str);
            }

        }

    }

    printf(
"\n");

}


posted on 2010-04-15 13:02 付翔 阅读(257) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜