poj2271--HTML
本题锻炼字符串的处理 scanf("%s",s) or strstr or strlen 很好的利用,其他没什么好讲的,注意长度刚好80在上一行输出,附代码。
View Code
1 #include <stdio.h> 2 #include <string.h> 3 4 char s[100]; 5 6 7 int main(void) 8 { 9 int t,len=0; 10 while(scanf("%s",s)!=EOF) 11 { 12 if(strstr(s,"<br>")) 13 { 14 printf("\n"); 15 len = 0; 16 } 17 else if(strstr(s,"<hr>")) 18 { 19 if(len>0) 20 printf("\n"); 21 printf("--------------------------------------------------------------------------------\n"); 22 len = 0; 23 } 24 else 25 { 26 t = strlen(s); 27 if(t + len > 80) 28 { 29 printf("\n"); 30 len = t + 1; 31 printf("%s ",s); 32 33 } 34 else 35 { 36 len += t + 1; 37 printf("%s ",s); 38 } 39 } 40 } 41 return 0; 42 }


浙公网安备 33010602011771号