Advertisement
Guest User

Untitled

a guest
Apr 7th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.59 KB | None | 0 0
  1. import std.stdio;
  2. import std.file;
  3.  
  4. import stdx.data.json;
  5.  
  6. int main(string[] args) {
  7.   string text = readText("../1.json");
  8.   auto jval = parseJSONValue(text);
  9.   assert(!text.length);
  10.   auto coordinates = jval.get!(JSONValue[string])["coordinates"].get!(JSONValue[]);
  11.   double x = 0;
  12.   double y = 0;
  13.   double z = 0;
  14.  
  15.   foreach (val; coordinates) {
  16.     x += val.opt("x").coerce!double;
  17.     y += val.opt("y").coerce!double;
  18.     z += val.opt("z").coerce!double;
  19.   }
  20.  
  21.   printf("%.8f\n%.8f\n%.8f\n", x / coordinates.length, y / coordinates.length, z / coordinates.length);
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement