GitHub PullRequestReviewCommentEvent at 2014-04-01 10:24:39
Repository: cpp_craft_0314
Actor: marozau
Payload: {"comment":{"url":"https://api.github.com/repos/marozau/cpp_craft_0314/pulls/comments/11154608","id":11154608,"diff_hunk":"@@ -0,0 +1,131 @@\n+//2\n+#include <fstream>\n+#include <string>\n+#include <stdexcept>\n+#include <map>\n+#include <set>\n+#include <reader.h>\n+#include <writer.h>\n+#include<iostream>\n+\n+#include <boost/ref.hpp>\n+\n+typedef  std::map<unsigned,int> mmap;\n+struct data\n+\t{\n+\t\tunsigned type,time,length;\n+\t\tchar *msg;\n+\t\tfriend io::bin_reader& operator>>(io::bin_reader &in,data &obj);\n+\t\tsize_t get_size()\n+\t\t{\n+\t\t\treturn sizeof(unsigned)*3+length;\n+\t\t}\n+\t\tdata():msg(NULL){}\n+\t\t~data()\n+\t\t{\n+\t\t\tdelete []msg;\n+\t\t}\n+\t};\t\n+io::bin_reader& operator>>(io::bin_reader &in,data &obj)\n+\t{\n+\t\tin.read(obj.type);\n+\t\tin.read(obj.time);\n+\t\tin.read(obj.length);\n+\t\tif ( obj.length )\n+\t\t{\n+\t\t\tobj.msg=new char[obj.length+1];\n+\t\t\tin.read(obj.msg,obj.length);\n+\t\t}\n+\t\treturn in;\n+\n+\t}\n+class task\n+{\n+\n+\tdata current_data;\n+\tio::bin_reader in;\n+\tstatic const size_t max_memory=2048ul;\n+\tio::bin_writer out;\n+public:\n+\ttask()\n+\t\t: in(BINARY_DIR\"/input.txt\" ),out(BINARY_DIR\"/output.txt\")\n+\t{   \n+\t\tif (!in.is_open()) throw(std::logic_error(\"Can't open file\"));\n+\t\tif (!out.is_open()) throw(std::logic_error(\"Can't open file \"));\n+\t\t\n+\t}\n+\n+\n+\tvoid solve()\n+\t{   \n+\t\tmmap met,times;\n+\t\tstd::set<unsigned> last;\n+\t\tstd::map<unsigned,size_t> size;\n+\t\tin>>current_data;\n+\t\tunsigned curr_time=0;\n+\t\twhile (!in.eof())\n+\t\t{\n+\t\t\tif ( current_data.time != curr_time || last.find(current_data.type) == last.end() )\n+\t\t\t{\n+\t\t\t\tif (current_data.time!=curr_time)\n+\t\t\t\tlast.clear();\n+\t\t\t\tif (current_data.get_size()<=max_memory)\n+\t\t\t\t{\n+\t\t\t\t\tsize[current_data.type]=current_data.get_size();\n+\t\t\t\t\tif (last.find(current_data.type)==last.end())\n+\t\t\t\t\ttimes[current_data.type]++;\n+\t\t\t\t\tlast.insert(current_data.type);\t\t\t\t\t\n+\t\t\t\t\tmet[current_data.type]++;\n+\t\t\t\t}\n+\t\t\t\tcurr_time=current_data.time;\n+\t\t\t    in>>current_data;\t\t\t\t\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (current_data.get_size()+size[current_data.type]<=max_memory)\n+\t\t\t{\n+\t\t\t\tmet[current_data.type]++;\n+\t\t\t\tsize[current_data.type]+=current_data.get_size();\n+\n+\t\t\t}\t\t\t\n+\t\t\tcurr_time=current_data.time;\n+\t\t\tin>>current_data;\n+\t\t\t\n+\t\t}\n+\t\tfor (mmap::iterator it=met.begin();it!=met.end();it++)\n+\t\t{\n+\t\t\tunsigned i=it->first;\n+\t\t\tout.write(i);\n+\t\t\tconst double temp=static_cast<double>(it->second)/times[it->first];\n+\t\t\tout.write(temp);\n+\t\t}\n+\n+\t}\n+\t\n+\n+};\n+\n+\n+\t\n+void main()\n+{\n+\ttry\n+\t{\t\n+\t\ttask realization;\n+\t\trealization.solve();\n+\t}\n+\tcatch(const std::logic_error& message)\n+\t{\n+\t\tstd::cout<<message.what()<<\"\\n\";\n+\t}\n+\tcatch(std::exception )","path":"solutions/gleb_litvinov/2/sources/2_5/main.cpp","position":120,"original_position":120,"commit_id":"d9d033aa265b655339b399768a29e5310fc7b002","original_commit_id":"d9d033aa265b655339b399768a29e5310fc7b002","user":{"login":"marozau","id":1022560,"avatar_url":"https://avatars.githubusercontent.com/u/1022560?","gravatar_id":"c9b8691bfe6473ed20a9990de074a3b1","url":"https://api.github.com/users/marozau","html_url":"https://github.com/marozau","followers_url":"https://api.github.com/users/marozau/followers","following_url":"https://api.github.com/users/marozau/following{/other_user}","gists_url":"https://api.github.com/users/marozau/gists{/gist_id}","starred_url":"https://api.github.com/users/marozau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marozau/subscriptions","organizations_url":"https://api.github.com/users/marozau/orgs","repos_url":"https://api.github.com/users/marozau/repos","events_url":"https://api.github.com/users/marozau/events{/privacy}","received_events_url":"https://api.github.com/users/marozau/received_events","type":"User","site_admin":false},"body":"const std::exception&","created_at":"2014-04-01T10:24:39Z","updated_at":"2014-04-01T10:24:39Z","html_url":"https://github.com/marozau/cpp_craft_0314/pull/131#discussion_r11154608","pull_request_url":"https://api.github.com/repos/marozau/cpp_craft_0314/pulls/131","_links":{"self":{"href":"https://api.github.com/repos/marozau/cpp_craft_0314/pulls/comments/11154608"},"html":{"href":"https://github.com/marozau/cpp_craft_0314/pull/131#discussion_r11154608"},"pull_request":{"href":"https://api.github.com/repos/marozau/cpp_craft_0314/pulls/131"}}}}