首页 > 其他 > 详细

URAL 1881 Long problem statement

时间:2014-07-19 15:08:02      阅读:316      评论:0      收藏:0      [点我收藏+]

1881. Long problem statement

Time limit: 0.5 second
Memory limit: 64 MB
While Fedya was writing the statement of the problem GOV Chronicles, he realized that there might be not enough paper to print the statements. He also discovered that his text editor didn‘t have the feature of calculating the number of pages in a text. Then Fedya decided to write a program that would calculate the number of pages for any given text.
Fedya knew that there were h lines on each page and w symbols in each line. Any two neighboring words in a line were separated by exactly one space. If there was no place for a word in a line, Fedya didn‘t hyphen it but put the whole word at the beginning of the next line.

Input

The first line contains the integers h, w, and n, which are the number of lines on a page, the number of symbols in a line, and the number of words in the problem statement, respectively (1 ≤ h, w ≤ 100; 1 ≤ n ≤ 10 000). The statement written by Fedya is given in the following n lines, one word per line. The words are nonempty and consist of uppercase and lowercase English letters and punctuation marks (period, comma, exclamation mark, and question mark); the length of each word is at most w. The total length of all the words is at most 10 000.

Output

Output the number of pages in the problem statement.

Sample

inputoutput
3 5 6
To
be
or
not
to
be
2
bubuko.com,布布扣
 1 #include<iostream>  
 2 #include<string.h>  
 3 #include<stdio.h>  
 4 #include<ctype.h>  
 5 #include<algorithm>  
 6 #include<stack>  
 7 #include<queue>  
 8 #include<set>  
 9 #include<math.h>  
10 #include<vector>  
11 #include<map>  
12 #include<deque>  
13 #include<list>  
14 using namespace std; 
15 int main()
16 {
17     char s[10010];
18     int a,b,c,d,x=1,e,f=0;
19     scanf("%d%d%d%",&a,&b,&c);
20     gets(s);
21     f=strlen(s);
22     e=1;
23     c--;
24     while(c--)
25     {
26         gets(s);
27         d=strlen(s);
28         if(f+d+1>b)
29         {
30             e++;
31             f=d;
32         }
33         else
34             f+=(d+1);
35         if(e>a)
36         {
37             e=1;
38             x++;
39         }
40     }
41     printf("%d\n",x);
42     return 0;
43 }
View Code

URAL 1881 Long problem statement,布布扣,bubuko.com

URAL 1881 Long problem statement

原文:http://www.cnblogs.com/qscqesze/p/3854184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!