Warm up 16 Ragged Right
| Ragged Right |
| Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB |
| Total submit users: 38, Accepted users: 37 |
| Problem 12786 : No special judgement |
|
Problem description 又是一道感人的出入方式的傻逼题啊! |
| Word wrapping is the task of deciding how to break a paragraph of text into lines. For aesthetic reasons, we’d like all the lines except the last one to be about the same length. For example, we would say the text on the left looks less ragged than the text on the right: This is a This paragraph is a paragraph of text. of text. Your job is to compute a raggedness value for an arbitrary paragraph of text. We’ll measure raggedness in a way similar to the T EX typesetting system. Let n be the length, measured in characters, of the longest line of the paragraph.If some other line contains only m characters, then we’ll charge a penalty score of (n − m)^2 for that line. The raggedness will be the sum of the penalty scores for every line except the last one. |
| Input |
| Input consists of a single paragraph of text containing at most 100 lines. Each line of the paragraph contains a sequence of between 1 and 80 characters (letters, punctuation characters, decimal digits and spaces). No line starts or ends with spaces. The paragraph ends at end of file. |
| Output |
| Print out a single integer, the raggedness score for paragraph. |
| Sample Input |
Sample Input 1 some blocks of text line up well on the right, but some don’t. Sample Input 2 this line is short this one is a bit longer and this is the longest of all. |
| Sample Output |
Sample Input 1 283 Sample Input 2 218 |
| Problem Source |
| HNU Contest |
| Submit Discuss Judge Status Problems Ranklist |
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <cstdlib> 10 #include <iostream> 11 #include <algorithm> 12 using namespace std; 13 #define maxn 105 14 #define ll long long 15 #define mod 1000000007 16 #define INF 0x7fffffff 17 #define eps 1e-8 18 int n, m; 19 ll gcd(ll n, ll m){ return m ? gcd(m, n%m) : n; } 20 char s[maxn]; 21 int a[maxn]; 22 int main(){ 23 /*int t; 24 scanf("%d", &t); 25 while (t--){ 26 scanf("%I64d", &n); 27 28 }*/ 29 int k = 0; 30 int ma = -INF; 31 while (1){ 32 if (gets(s) == NULL)break; 33 n = strlen(s); 34 a[k++] = n; 35 if (ma < n)ma = n; 36 } 37 int sum = 0; 38 for (int i = 0; i < k - 1; i++) 39 sum += (ma - a[i]) * (ma-a[i]); 40 printf("%d\n", sum); 41 return 0; 42 }
浙公网安备 33010602011771号