hdu Write a simple HTML Browser

本文提供了一种解决HDU 1088编程题的方法,通过C语言实现文本格式化输出,确保输出内容符合特定格式要求,如换行符和水平线的正确使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1088

 

对比输出

 

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <ctype.h>
 7 #include <iomanip>
 8 #include <queue>
 9 #include <map>
10 #include <stdlib.h>
11 using namespace std;
12 
13 char word[81];
14 
15 int main()
16 {
17     int len,i;
18     int cp=-1;
19     while(scanf("%s",word)==1){
20         if(strcmp(word,"<br>")==0){
21             putchar('\n');
22             cp=-1;
23         }
24         else if(strcmp(word,"<hr>")==0){
25             if(cp!=-1)
26                 putchar('\n');
27             for(i=0;i<80;i++)
28                 putchar('-');
29             putchar('\n');
30             cp=-1;
31         }
32         else{
33             len=strlen(word);
34             if(cp+len+1<80){
35                 if(cp!=-1)
36                     putchar(' ');
37                 printf("%s",word);
38                 cp+=(len+1);
39             }
40             else{
41                 putchar('\n');
42                 printf("%s",word);
43                 cp=len;
44             }
45         }
46     }
47     putchar('\n');
48     return 0;
49 }
View Code

 

转载于:https://www.cnblogs.com/wangmengmeng/p/4871888.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值