Browse Source

using <iomanip> to format output

webturing 4 years ago
parent
commit
0859ae817e
4 changed files with 7 additions and 8 deletions
  1. 3 4
      B.cpp
  2. 1 1
      C.cpp
  3. 1 1
      D.cpp
  4. 2 2
      E.cpp

+ 3 - 4
B.cpp

@@ -3,10 +3,9 @@
 using namespace std;
 
 int main() {
-    int x, y, z;
-    for (x = 0; x < 20; x++)
-        for (y = 1; y < 33; y++) {
-            z = 100 - x - y;
+    for (int x = 0; 5 * x <= 100; x++)
+        for (int y = 1; 3 * y <= 100; y++) {
+            int z = 100 - x - y;
             if (5 * x + 3 * y + z / 3 == 100 && z % 3 == 0) {
                 cout << "cock=" << x << ",hen=" << y << ",chicken=" << z << endl;
             }

+ 1 - 1
C.cpp

@@ -4,7 +4,7 @@ using namespace std;
 
 int main() {
     for (double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;) {
-        cout << setiosflags(ios::fixed) << setprecision(2)
+        cout << fixed << setprecision(2)
              << hypot(x1 - x2, y1 - y2) << endl;
     }
     return 0;

+ 1 - 1
D.cpp

@@ -5,7 +5,7 @@ const double pi = atan(1.0) * 4;
 
 int main() {
     for (double r; cin >> r;) {
-        cout << setiosflags(ios::fixed) << setprecision(3)
+        cout << fixed << setprecision(3)
              << 4.0 * pi * pow(r, 3) / 3 << endl;
     }
     return 0;

+ 2 - 2
E.cpp

@@ -1,13 +1,13 @@
 #include <bit/stdc++.h>
 
 using namespace std;
+const double PI = atan(1.0) * 4;
 
 int main() {
-    const double PI = atan(1.0) * 4;
     int n;
     double r;
     for (cin >> n; cin >> r, n--;) {
-        cout << setiosflags(ios::fixed) << setprecision(6) << PI * r * r << endl;
+        cout << fixed << setprecision(6) << PI * r * r << endl;
     }
     return 0;
 }