HDOJ 1088 Write a simple HTML Browser
http://acm.hdu.edu.cn/showproblem.php?pid=1088
字符串的控制,理解好题意.
不过这题还是有点变态的.
#include <iostream> using namespace std; char str[200]; #define hr "--------------------------------------------------------------------------------" int main() { int i,j,k,n,m,t; int sum = 0; // freopen("12.txt","r",stdin); // freopen("123.txt","w",stdout); while (scanf("%s",str)!=EOF) { if (strcmp(str,"<br>") == 0) { sum = 0; printf("/n"); } else if (strcmp(str,"<hr>") == 0) { if (sum == 0) { printf("%s/n",hr); } else { sum = 0; printf("/n%s/n",hr); } } else { if (sum==0) { printf("%s",str); sum += strlen(str); } else { if (sum + strlen(str) + 1<=80) { printf(" %s",str); sum += strlen(str) + 1; } else { printf("/n"); printf("%s",str); sum = strlen(str); } } } } printf("/n"); // fclose(stdout); return 0; }