/** execute an rpc command and store the results in a string. */ void executerpc ( rpc::context& context, std::string& output, yieldstrategy const& strategy) { boost::optional <handler const&> handler; if (auto error = fillhandler (context, handler)) { auto wo = stringwriterobject (output); auto&& sub = addobject (*wo, jss::result); inject_error (error, sub); } else if (auto method = handler->objectmethod_) { auto wo = stringwriterobject (output); getresult (context, method, *wo, handler->name_); } else if (auto method = handler->valuemethod_) { auto object = json::value (json::objectvalue); getresult (context, method, object, handler->name_); if (strategy.streaming == yieldstrategy::streaming::yes) output = jsonasstring (object); else output = to_string (object); } else { // can't ever get here. assert (false); throw rpc::jsonexception ("rpc handler with no method"); } }
int main(void){ double a = 4.0; double b = 3.0; double x = -2.0; printf("Result: %f", getresult(a, b, x)); getchar(); return 0; }
vector<vector<int> > combinationSum2(vector<int> &num, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> now; vector<vector<int> > res; sort(num.begin(), num.end()); getresult(num, target, 0, now, res); return res; }
bool openRead(const char *_query) { transformQuery(_query,false); close(true); eos = false; readok = true; writeok = false; savesize = (rfs_fpos_t)-1; return getresult(); }
void getresult(vector<vector<int>> &res, vector<int> &row, int n) { int i = row.empty() ? 2:row.back(); for(;i<=n/i;++i) { if(n%i==0) { row.push_back(i); row.push_back(n/i); res.push_back(row); row.pop_back(); getresult(res,row,n/i); row.pop_back(); } } }
/* * Fetch, compute, and print the timing for one task group. */ static void calcresult(unsigned groupid, time_t startsecs, unsigned long startnsecs, char *buf, size_t bufmax) { time_t secs; unsigned long nsecs; getresult(groupid, &secs, &nsecs); /* secs.nsecs -= startsecs.startnsecs */ if (nsecs < startnsecs) { nsecs += 1000000000; secs--; } nsecs -= startnsecs; secs -= startsecs; snprintf(buf, bufmax, "%lld.%09lu", (long long)secs, nsecs); }
void getresult(vector<int> &num, int lack, int st, vector<int> &now, vector<vector<int> > &res) { if (lack==0) { res.push_back(now); return; } int i = st; while (i<num.size()) { if (num[i]>lack) break; now.push_back(num[i]); getresult(num, lack-num[i], i+1, now, res); i++; while (i<num.size() && num[i]==num[i-1]) i++; now.pop_back(); } }
static int reverse_lookup (question_t *q, char *name, DWORD nameserver) { int i, ret; int ready = 0; udp_Socket dom_sock; if (!nameserver || /* no nameserver, give up */ dns_timeout == 0) return (0); udp_open (&dom_sock, 997, nameserver, 53, NULL); for (i = 2; i < 17 && !_resolve_exit; i *= 2) { sock_write ((sock_type*)&dom_sock, (BYTE*)q, sizeof(*q)); ip_timer_init (&dom_sock, i); do { kbhit(); tcp_tick ((sock_type*)&dom_sock); if (watcbroke || (_resolve_hook && (*_resolve_hook)() == 0)) { _resolve_exit = 1; break; } if (ip_timer_expired(&dom_sock) || chk_timeout(resolve_timeout)) break; if (sock_dataready((sock_type*)&dom_sock)) ready = 1; } while (!ready); } if (ready) ret = getresult (&dom_sock, name); else ret = 0; sock_close ((sock_type*)&dom_sock); return (ret); }
std::string Monitor::getresultstringonlyvalues()const{ //return only the values, not the header as a string //check wether pp2 and pp1 still exists try{ //getvalue doesnt crash on a bad pointer if (type!=3){ const bool b2=pp2->isbound(); pp2->setbound(false); pp2->setbound(b2); } } catch(...){ //remove this monitor pp1->killmonitor(); return ""; } std::ostringstream s; //add header value and sigma if (s << getresult()<< "\t"<< getsigma()){ // conversion worked return s.str(); } return ""; //in case conversion didn't work }
vector<vector<int>> getFactors(int n) { vector<vector<int>> res; vector<int> row; getresult(res,row,n); return res; }
int main() { clock_t start,finish; double duration; int ret = 0; int one_size=320; char* file_name=malloc(50*sizeof(char)); file_name=strcpy(file_name,"test.xml"); char * xpath_name=malloc(50*sizeof(char)); xpath_name=strcpy(xpath_name,"XPath.txt"); printf("Welcome to the XML lexer program! Your file name is test.xml\n\n"); printf("begin to load the file\n"); start=clock(); int n=load_file(file_name); //load file into memory printf("finish loading the file. \n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for loading the file is %lf\n",duration); sleep(1); if(n==-1) { printf("There are something wrong with the xml file, we can not load it. Please check whether it is placed in the right place."); exit(1); } printf("begin to deal with XML file\n"); start=clock(); char* xmlPath="/company/develop/programmer"; xmlPath=ReadXPath(xpath_name); if(strcmp(xmlPath,"error")==0) { printf("There are something wrong with the XPath file, we can not load it. Please check whether it is placed in the right place."); exit(1); } createAutoMachine(xmlPath); //create auto machine by xmlpath printf("The basic structure of the automata is (from to end):\n"); int i,rc; char *out=" is an output"; for(i=1;i<=machineCount;i=i+2) { if(i==1){ printf("%d",stateMachine[i].start); } printf(" (str:%s",stateMachine[i].str); if(stateMachine[i].isoutput==1) { printf("%s",out); } printf(") %d",stateMachine[i].end); } printf("\n"); for(i=machineCount;i>0;i=i-2) { if(i==machineCount){ printf("%d (str:%s) %d",stateMachine[i].start,stateMachine[i].str,stateMachine[i].end); } else { printf(" (str:%s) %d",stateMachine[i].str,stateMachine[i].end); } } printf("\n\n"); main_function(); printf("finish dealing with the file\n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for dealing with the file is %lf\n",duration); printf("\n"); printf("All the subthread ended, now the program is merging its results.\n"); printf("begin to merge results\n"); start=clock(); ResultSet set=getresult(n); printf("The mappings for text.xml is:\n"); print_result(set); printf("finish merging these results\n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for merging these results is %lf\n",duration); system("pause"); return 0; }