#include <iostream> #include <iomanip> #include <string> #include <stdio.h> #include <math.h> using namespace std; int main() { int n; int index = 1; string x; while (cin >> n) { if (n == 0) break; double s = 0;//总面积 for(int i = 0;i<n;i++) { double x1 = 0, y1= 0, x2=0, y2=0;//默认每个图形都是正多边形,所以只需记录一份边长即可 int m;//表示本平面点的个数 double a = 0;//边长 cin >> m >> x1 >> y1 >> x2 >> y2; //这里需要对输入缓存做一次清空,不然本次输入多余的部分将会对下一次读取影响 getline(cin, x); a = sqrt((y1 - y2)*(y1 - y2) + (x1 - x2)*(x1 - x2)); switch (m) { case 3: s += 1.73205 / 4 * a * a; break; case 4: s += a * a; break; case 5: s += 1.72048 * a * a; break; case 6: s += 1.73205 / 4 * a*a * 6; break; case 7: s += 3.63391 * a * a; break; case 8: s += 4.82843 * a*a; break; default: break; } } printf("Case #%d: %.4f\n", index++, s); } } |
Double click to view unformatted code.