// Compute the mapping between linear array and a hypercube corresponding /// to a single generator tree void ComputeOneGenMapping(Permut& genMap, const OneGeneratorTree& T) { Vec<long> dims(INIT_SIZE, T.getNleaves()); Vec<long> coefs(INIT_SIZE,T.getNleaves()); for (long i=T.getNleaves()-1, leaf=T.lastLeaf(); i>=0; i--, leaf=T.prevLeaf(leaf)) { dims[i] = T[leaf].getData().size; coefs[i] = T[leaf].getData().e; } // A representation of an integer with digits from dims Vec<long> rep(INIT_SIZE, T.getNleaves()); for (long i=0; i<rep.length(); i++) rep[i]=0; // initialize to zero // initialize to all zero long sz = T[0].getData().size; genMap.SetLength(sz); for (long i=0; i<sz; i++) genMap[i]=0; // compute the permutation for (long i=1; i<sz; i++) { addOne(rep, dims); // representation of i in base dims for (long j=0; j<coefs.length(); j++) { long tmp = MulMod(rep[j], coefs[j], sz); genMap[i] = AddMod(genMap[i], tmp, sz); } } }
int main() { int x = 1; int y = foo(x); y = addOne(bar(x), returnOne()); ASSERT(y == x+1); return y; }
int main(int argc, char* argv[]) { int i = 0; printf("add one: %d\n", addOne(i)); printf("add two: %d\n", addTwo(i)); return i; }
int main() { int x = 1; int y; y = addOne(1, returnOne()); ASSERT(y == x+1); return y; }
string addBinary(string a, string b) { string result; int carry = 0; int ia,ib; ia = a.length() - 1,ib = b.length() - 1; while(ia >= 0 && ib >= 0) { int tmp = carry + (a[ia--] - '0') + (b[ib--] - '0'); result.insert(result.begin(),tmp % 2 + '0'); carry = tmp / 2; } addOne(result,a,ia,carry); addOne(result,b,ib,carry); //cout << carry << endl; if(carry) result.insert(result.begin(),carry + '0'); return result; }
void flagOptions::completeSummary(int count, int other, bool summ){ int mult = count * other; while(summ){ shares += count; completed = addOne(completed); transfer = addTwo(transfer, mult); for(int i = 0; i < 2; i++) commision = ((count*other) / 100 )+ commision; return; } }
/* * 若是"Enter Chat Room"按钮被按下: * { * 若昵称不合法,显示警告信息并清空昵称输入框 * 反之: * { * 记录临时昵称 * 隐藏此时显示的所有部件,然后显示聊天时该有的所有部件 * 在聊天内容文本快上添加"我加入了"的消息记录 * 将自己的昵称和ip加入到昵称表和ip表中 * 广播"我来了"的消息 * } * } * 若是"Submit"按钮被按下 且 输入的聊天内容不为空: * { * 在聊天文本快上添加"自己发送了xxx信息" * 清空聊天输入框 * 广播"我发送了xxx"的消息 * } */ bool ChatWindow::eventFilter(QObject *obj, QEvent *event) { if(obj==_enterChat && event->type()==QEvent::MouseButtonPress && _inputUser->text()!="") {//若是按下 进入聊天室 按钮 if(validUsername(_inputUser->text())) //若昵称合法 { _username=_inputUser->text(); //记录临时昵称 //隐藏 未进入聊天室时候的 所有ui部件 _zb->hide(); _userLabel->hide(); _inputUser->hide(); _enterChat->hide(); //显示 进入聊天室后的 所有ui部件 _label1->setVisible(true); _label2->setVisible(true); _room->setVisible(true); _allContents->setVisible(true); _inputContent->setVisible(true); _submit->setVisible(true); //在聊天内容文本块中添加"我来了"的消息 updateAllContents("",QString("!report: ").append(_username).append(" join")); //将自己的昵称和ip加入到昵称表和ip表中 addOne(_username,getIPv4()); //广播"我来了"的消息 QByteArray bytes=pack_Come(_username,getIPv4()); _sender->writeDatagram(bytes,bytes.length(),QHostAddress::Broadcast,_port); }else{ //给出提示 _userLabel->setText("only allow a-z,A-Z,0-9!"); _userLabel->setStyleSheet("color:#880000"); //清理输入框内的内容 _inputUser->clear(); } return true; } if(obj==_submit && event->type()==QEvent::MouseButtonPress && _inputContent->toPlainText()!="") {//若是按下 提交聊天输入 按钮 //在聊天文本快上添加"自己发送了xxx信息" QString str=_inputContent->toPlainText(); updateAllContents("[self]",str); //清空聊天输入框 _inputContent->clear(); //广播"我发送了xxx"的消息 QByteArray bytes=pack_Talk(_username,str); _sender->writeDatagram(bytes,bytes.length(),QHostAddress::Broadcast,_port); return true; } return QWidget::eventFilter(obj,event); }
void Obstacle::update() { if (GAME_STATUS != GAME_STATUS_PLAYING) return; addCount++; if (addCount == 60) { addOne(0); addCount = 0; } for (int i = obstacleList->count() - 1; i >= 0; i--) { auto s = (Sprite*)obstacleList->getObjectAtIndex(i); s->setPositionX(s->getPositionX() - 3); if (s->getPositionX() < -s->getContentSize().width / 2) { obstacleList->removeObjectAtIndex(i); this->removeChild(s); } } }
int main() { const size_t WIDTH = 15; const size_t HEIGHT = 4; // Create and fill a 2D array ScalarT* mem = ( ScalarT* )malloc( sizeof(ScalarT) * WIDTH * HEIGHT ); for( size_t i = 0; i < WIDTH * HEIGHT; ++i ) mem[i] = i; std::cout << "Input array: " << std::endl; print( mem, WIDTH, HEIGHT ); std::cout << std::endl; addOne( mem, WIDTH, HEIGHT ); std::cout << std::endl; std::cout << "Result array: " << std::endl; print( mem, WIDTH, HEIGHT ); free( mem ); return EXIT_SUCCESS; }
/* * 1.从昵称表中删除user,从ip表中删除ip * 2.清空ui上的用户列表,然后根据昵称表和ip表重新往ui上添加聊天室内的用户数据 * 3.在聊天内容文本快上添加"某某离开了"的消息记录 */ void ChatWindow::removeOne(const QString &user,const QString &ip) { //从昵称表中删除user,从ip表中删除ip int N=static_cast<int>(_ipList.size()); int index=-1; for(int i=0;i<N;i++) { if(QString(_ipList[i])==ip) { index=i; break; } } if(index!=-1){ //若原表中有这个用户 _userList.erase(_userList.begin()+index); _ipList.erase(_ipList.begin()+index); //清空ui上的用户列表,然后根据昵称表和ip表重新往ui上添加聊天室内的用户数据 _room->clear(); for(int i=0;i<N-1;i++) addOne(_userList[i],_ipList[i]); } //在聊天内容文本快上添加"某某离开了"的消息记录 updateAllContents("",QString("!report: ").append(user).append(" leave")); }
int main(){ int n =15; printf("increament: %d ", addOne(n)); }
/*1. 收到come报文: * { 加入用户列表,返回receiveCome报文 } *2. 收到receiveCome报文: * { 将对方用户名和ip加入用户列表 } *3. 收到leave报文: * { 根据对方ip从用户列表去除 } *4. 收到talk报文: * { 更新聊天内容 } */ void ChatWindow::onReadyRead() { QByteArray bytes; bytes.resize(_receiver->pendingDatagramSize()); _receiver->readDatagram(bytes.data(),bytes.size()); QDataStream in(&bytes,QIODevice::ReadOnly); quint16 size; int type; in>>size>>type; switch(type) { case _TypeCome:{ //收到 某人进入聊天室的消息 QString user,ip; in>>user>>ip; if(ip!=getIPv4()){ //不把本机加入聊天室的消息再次显示到聊天文本块 //不然就显示两次了 updateAllContents("",QString("!report: ").append(user).append(" join")); addOne(user,ip); QByteArray response=pack_ResponseCome(_username,getIPv4()); _sender->writeDatagram(response,response.length(),QHostAddress::Broadcast,_port); } break; } case _TypeResponseCome:{ //收到 某人响应你的进入 的消息(因为你进入聊天室时会广播消息给所有人) QString user,ip; in>>user>>ip; int N=static_cast<int>(_ipList.size()); int index=-1; for(int i=0;i<N;i++) { if(QString(_ipList[i])==ip) { index=i; break; } } if(index==-1) addOne(user,ip); break; } case _TypeLeave:{ //收到某人离开聊天室的消息 QString user,ip; in>>user>>ip; if(user!="") removeOne(user,ip); break; } case _TypeTalk:{ //收到某人说了什么话的消息 QString user,str; in>>user>>str; if(user!=_username) updateAllContents(user,str); break; } } //递归接收消息 if(_receiver->pendingDatagramSize()>0) onReadyRead(); }
int main(int argc, char **argv) { //check for arguments from the cli if(argc < 3) { printf("There must be at least one subnet and one IP address.\n"); return -1; } //Initialize variables int soct1, soct2, soct3, soct4; //used to hold numbers for address between each dot int ioct1, ioct2, ioct3, ioct4; //used to hold numbers for address between each dot int numHosts; //holds # of hosts in the network to scan for //Read in subnet and ip address from cli char* sub_addr_dot=argv[1]; //char array of cli input char* ip_addr_dot=argv[2]; //char array of cli input //Parse strings to get ints to work with sscanf(argv[1], "%d.%d.%d.%d", &soct1, &soct2, &soct3, &soct4); sscanf(argv[2], "%d.%d.%d.%d", &ioct1, &ioct2, &ioct3, &ioct4); //Convert to binary and obtain network address u_long ip_addr_long, sub_addr_long, net_addr_long; //holds addresses in binary ip_addr_long = inet_addr(ip_addr_dot); //convert ip to binary sub_addr_long = inet_addr(sub_addr_dot); //convert subnet to binary net_addr_long = inet_addr(ip_addr_dot) & inet_addr(sub_addr_dot); //get network address by bitwise AND //Find number of hosts to go through for loop numHosts = calcHosts(soct1, soct2, soct3, soct4); //move network address to a variable that will change as we go through the //loop for the number of hosts we calculated for the subnet u_long current_addr_long = net_addr_long; int i; //i is used to iterate through the loop struct in_addr currentAddy; //this struct is used to print out the current address for(i=1; i <= numHosts; i++) { addOne(¤t_addr_long); //move to the next host in the network currentAddy.s_addr = current_addr_long; //move current address into struct printf("Host: %s\n", inet_ntoa(currentAddy)); //print out current address //ip work char* addr_ptr; //holds current address as a char array struct hostent *hostPtr; //stuct to hold host data addr_ptr = (char *) ¤t_addr_long; //hold address in char array hostPtr = gethostbyaddr(addr_ptr, 4, AF_INET); //gets data for host in struct if(hostPtr == NULL) printf("Host %s not found\n", inet_ntoa(currentAddy)); //print out current address else { printf("The official name of the site is: %s\n", hostPtr->h_name); //prints the official hostname for the site int aliasCount=1; //helps output proper number for the alias when printing while(*(hostPtr->h_aliases) != NULL) //loops through all aliases and prints them { printf("Alias %d: %s\n", aliasCount, *(hostPtr->h_aliases)); //print alias aliasCount++; //increment number of aliases hostPtr->h_aliases++; //go to next alias position } //Display IP addresses struct in_addr *addrPtr; //a separate in_addr struct used to print IPs from host info while(*(hostPtr->h_addr_list) != NULL) //loop through all IP's { addrPtr = (struct in_addr *) *hostPtr->h_addr_list; //get ip from host info to in_addr struct printf("IP address: %s\n", inet_ntoa(*addrPtr)); //print info for address hostPtr->h_addr_list++; //go to the next address } } printf("===================================\n"); //print a separating line for the next host } //network information struct in_addr networkAddy; //used to hold network address networkAddy.s_addr = net_addr_long; //store calculated network address printf("Network Address: %s\n", inet_ntoa(networkAddy)); //print the network address return 0; }
bool GuiCombat::CheckUserInput(JButton key) { if (NONE == cursor_pos) return false; DamagerDamaged* oldActive = active; int x,y; if(observer->getInput()->GetLeftClickCoordinates(x, y)) { // determine if OK button was clicked on if (ok.width) { if (didClickOnButton(ok, x, y)) { cursor_pos = OK; } } // position selected card if (BLK == cursor_pos) { DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y)); // find the index into the vector where the current selected card is. int c1 = 0, c2 = 0; int i = 0; for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it) { if ( *it == selectedCard ) c2 = i; else if ( *it == active) c1 = i; i++; } // simulate pressing the "Left/Right D-Pad" control c1 - c2 times if ( c1 > c2 ) // card selected is to the left of the current active card { for (int x = 0; x < c1 - c2; x++) shiftLeft(); } else if ( c1 < c2 ) { for (int x = 0; x < c2 - c1; x++) shiftRight( oldActive ); } } } switch (key) { case JGE_BTN_OK: if (BLK == cursor_pos) { if (ORDER == step) observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } else { signed damage = activeAtk->card->stepPower(step); for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); *it != active; ++it) damage -= (*it)->sumDamages(); signed now = active->sumDamages(); damage -= now; if (damage > 0) addOne(active, step); else if (activeAtk->card->has(Constants::DEATHTOUCH)) for (; now >= 1; --now) removeOne(active, step); else for (now -= active->card->toughness; now >= 0; --now) removeOne(active, step); } } else if (ATK == cursor_pos) { active = activeAtk->blockers.front(); active->zoom = kZoom_level3; cursor_pos = BLK; } else if (OK == cursor_pos) { clickOK(); } break; case JGE_BTN_CANCEL: if (BLK == cursor_pos) { oldActive->zoom = kZoom_level2; active = activeAtk; cursor_pos = ATK; } return true; case JGE_BTN_LEFT: shiftLeft(); break; case JGE_BTN_RIGHT: shiftRight( oldActive ); break; case JGE_BTN_DOWN: if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break; removeOne(active, step); break; case JGE_BTN_UP: if (ORDER == step || BLK != cursor_pos) break; addOne(active, step); break; case JGE_BTN_PRI: active = activeAtk = NULL; cursor_pos = OK; break; case JGE_BTN_NEXT: if (!options[Options::REVERSETRIGGERS].number) return false; active = activeAtk = NULL; cursor_pos = OK; break; case JGE_BTN_PREV: if (options[Options::REVERSETRIGGERS].number) return false; active = activeAtk = NULL; cursor_pos = OK; break; default: ; } if (oldActive != active) { if (oldActive && oldActive != activeAtk) oldActive->zoom = kZoom_level2; if (active) active->zoom = kZoom_level3; if (ATK == cursor_pos) remaskBlkViews(dynamic_cast<AttackerDamaged*> (oldActive), static_cast<AttackerDamaged*> (active)); } if (OK == cursor_pos) ok.zoom = 1.5; else ok.zoom = kZoom_none; return true; }