int main() { CList *head = new CList; head->value = 0; head->next = NULL; printf("Counting - for every round of a cyclic list remove the k-th element, while not in the list will be only one. Enter the length of the list and number of the last element. Will be calculated the numbers of k before n!. \n\nn = "); int n = 0; scanf("%i", &n); printf("\nlast = "); int last = 0; scanf("%i", &last); long nFact = 1; for (int i = 1; i <= n; i++) nFact = nFact * i; List *lhead = new List; lhead->next = NULL; for (int k = 1; k <= nFact; k++) { fill(head, n); CList *tmp = head; while (lengh(head) != 1) { for (int c = 1; c < k; c++) { tmp = tmp->next; } del(head, returnNum(head, tmp->next)); } if (tmp->next->value == last) ladd(lhead, k, 1000); del(head, 1); } printf("\n\nk = {"); lprintList(lhead); printf("}\n"); removeList(head); lremoveList(lhead); scanf("%*"); delete lhead; delete head; return 0; }
void ModPhpHandler::inChild(int *p, const char *bin, const std::string& uri, zia::api::http::ITransaction & transac, std::istream& is) { std::string argsstr, pipeSize, queryString, scriptFilename; if (uri.find("?") != std::string::npos) argsstr = uri.substr(uri.find("?") + 1); std::cout << "argsstr = " << argsstr << std::endl; if (dup2(p[1], 1) == -1) std::cerr << "dup2 failed in child" << std::endl; if (dup2(p[0], 0) == -1) std::cerr << "dup2 failed in child" << std::endl; char* tab[6]; std::string lengh("CONTENT_LENGTH="); is.seekg(0, std::ios::end); int is_size = is.tellg(); tab[0] = const_cast<char*>((lengh + inttostr(is_size)).data()); tab[1] = "REQUEST_METHOD=POST"; tab[2] = "CONTENT_TYPE=application/x-www-form-urlencoded"; queryString = "QUERY_STRING=" + argsstr; tab[3] = const_cast<char*>(queryString.data()); scriptFilename = "SCRIPT_FILENAME=" + transac.getRequest().getPath(); tab[4] = const_cast<char*>(scriptFilename.data()); tab[5] = NULL; char* arg[2]; arg[0] = const_cast<char*>(bin); arg[1] = NULL; if (execve(arg[0], arg, tab) == -1) { std::cerr << "Execvp failed " << std::endl; perror("execve"); } }