URL: http://acm.sdut.edu.cn/sdutoj/problem.php? Action = showproblem & problemid = 2411
The third ACM competition in Shandong province.
Note:
1. There can be no decimal point. You can use the decimal point and star number as separators to save the time.
2. There are not a few spaces. It is quite troublesome to use getline (). It is better to manually enter a string array.
3. inches is not the only separator. The phone name can contain the inches character, so the find_last_of ("inches") (I didn't use this method)
4. Pay attention to the result of 0.00.
5. If there are N spaces in the phone name, a space is output.
# Include <cstdlib> # include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <algorithm> # include <set> # include <map> # include <list> # include <queue> # include <vector> # define ll long # define INF 0x7fffffff # define e 1e-11 # define M 100 # define n 1000 using namespace STD; int m, n, T; char STR [N] [N]; int OK (char * Str) {If (strcmp (STR, "inches") = 0) return 1; return 0;} int main () {# ifndef online_judge F Reopen ("ex. in "," r ", stdin); # endif scanf (" % d % * C ", & T); int ncase = 0; while (t --) {double D; int n = 0; int sub; while (scanf ("% s", STR [N])! = EOF) {If (OK (STR [N]) {sub = N; // cannot exit} n ++; char c = getchar (); if (C = '\ n') break;} double A, B; sscanf (STR [sub + 1], "% lf * % lf", &, & B); sscanf (STR [Sub-1], "% lf", & D); For (INT I = sub + 2; I <n; I ++) for (Int J = 0; STR [I] [J]; j ++) STR [I] [J] = tolower (STR [I] [J]); printf ("case % d: the", ++ ncase); For (INT I = sub + 2; I <n; I ++) printf ("% s ", STR [I]); printf ("of"); For (INT I = 0; I <sub-1; ++ I) printf ("% s ", STR [I]); If (FABS (d) <E) // wa printf ("s PPI is %. 2lf. \ n ", 0.00); else printf ("'s PPI is %. 2lf. \ n ", SQRT (A * A + B * B)/d);} return 0 ;}