int insertSuffix(node *T, char *word){ int aux, i, j, k, size; char *palavra; size = lenght(word); if (!(palavra = malloc(sizeof(char)*(size + 1)))){ return 0; } for (i = 0; i < size; i++){ j = size - i - 1; k = 0; while(j < size){ palavra[k] = word[j]; k++; j++; } palavra[k] = '\0'; aux = insert(T, palavra); if (!aux){ return 0; } } return 1; }
void LoginScreen::update(float ft){ //CCdelaytime CCRepeat不用一起用。。 if(stage==1){//结束了,跳转页面 string ablePath = MyFileUtils::getWritablePath(); MyFileUtils::deleteDir(ablePath+"logo"); //HomePageScreen::deleteDir(); SWITCHTO_FATHER_SCREEN(HomePageScreen); //SWITCHTO_FATHER_SCREEN(MyGameScreen); return; } frm++; if(frm==30){ NetHander *net = new NetHander(); net->getLogo(); Callback *call = (Callback *)this; net->setCallBack(call); vecNet.push_back(net); //net->autorelease(); }else if(frm>=600){//10秒之后 if(!hasGetDownloadUrl){ CCLog("hasGetDownloadUrl stage 1"); stage = 1; } }else if(frm>=6000){ stage = 1; } if(!isTurn){ for(int i = 0;i<lenght(dian);i++){ dianOptin[i]+=10; dianOptin[i]%=500; int temp = dianOptin[i]>=250?(500-dianOptin[i]):dianOptin[i]; dian[i]->setOpacity(temp); dian[i]->setScale(0.5+((float)temp/2)/250); } if(icon){ if(icon->hasDownload){ if(icon->showTime<0){ if(isKeypressed(M_KEY_OK)){ downSprite->setPressed(); } }else{ showFrm++; if(showFrm>=icon->showTime*60){ downSprite->setPressed(); } } if(downSprite->isPress()){ CCLog("pressed stage 1"); stage = 1; } } } } Screen::update(ft); }
Vector2 Vector2::toPolarCoordinates() const { Real l = lenght(); if(l > 1e-4f) return Vector2(Angle::ATan2(y, x), l); else return Vector2::Zero; }
void max_heapify(HeapMax *heap_max, int i) { int l, r, max, aux; l = left(i); r = right(i); if(l <= lenght(heap_max) and heap_max->values[l] > heap_max->values[i]) max = l; else max = i; if(r <= lenght(heap_max) and heap_max->values[r] > heap_max->values[max]) max = r; if(max != i) { aux = heap_max->values[i]; heap_max->values[i] = heap_max->values[max]; heap_max->values[max] = aux; max_heapify(heap_max, max); }; };
void copy(char *word, char *other_word){ // word = other_word; int i, size; size = lenght(other_word); for (i = 0; i < size+1; i++){ word[i] = other_word[i]; } }
void ShowMousePicking (const dVector& p0, const dVector& p1) { dFloat radius = 0.25f; // set the color of the cube's surface GLfloat cubeColor[] = { 1.0f, 1.0f, 1.0f, 1.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, cubeColor); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cubeColor); glMaterialf(GL_FRONT, GL_SHININESS, 50.0); // set up the cube's texture glDisable(GL_TEXTURE_2D); GLUquadricObj *pObj; glPushMatrix(); dMatrix matrix (GetIdentityMatrix()); matrix.m_posit = p0; glMultMatrix(&matrix[0][0]); // Get a new Quadric off the stack pObj = gluNewQuadric(); gluQuadricTexture(pObj, true); gluSphere(pObj, radius, 10, 10); glPopMatrix(); glPushMatrix(); matrix.m_posit = p1; glMultMatrix(&matrix[0][0]); gluSphere(pObj, radius, 10, 10); gluDeleteQuadric(pObj); glPopMatrix(); dVector dir (p1 - p0); dFloat lenght (dir % dir); if (lenght > 1.0e-2f) { glPushMatrix(); lenght = sqrt (lenght); dMatrix align (dgYawMatrix(0.5f * 3.1426f)); align.m_posit.m_x = -lenght * 0.5f; matrix = align * dgGrammSchmidt(dir); matrix.m_posit += (p1 + p0).Scale (0.5f); glMultMatrix(&matrix[0][0]); // Get a new Quadric off the stack pObj = gluNewQuadric(); gluCylinder(pObj, radius * 0.5f, radius * 0.5f, lenght, 10, 2); gluDeleteQuadric(pObj); glPopMatrix(); } }
Real Vector2::normalize() { Real l = lenght(); if(l > 1e-08) { Real invLenght = 1 / l; x *= invLenght; y *= invLenght; } return l; }
Real Vector3::normalize() { Real len = lenght(); if(len > 1e-6f) { *this *= 1.f / len; return len; } else { aprodebug("Vector lenght is too short ! Normalization failed."); set(1,0,0); return 0; } }
DijkstraResult* dijkstra(Graph *graph, int source){ DijkstraResult* dijkstra_result; MinPriorityQueue min_priority_queue; int u; dijkstra_result = allocate_memory_dijkstra(graph->numbers_nodes); allocate_memory(&min_priority_queue, graph->numbers_nodes); initialize(dijkstra_result, &min_priority_queue, source, graph->numbers_nodes); build_min_heap(&min_priority_queue); while(lenght(&min_priority_queue) > 0){ u = extract_minimum(&min_priority_queue); for(int v = 0; v < graph->numbers_nodes; v++) relax(dijkstra_result, &min_priority_queue, graph, u, v); } return dijkstra_result; };
char *inverse(char *word){ int i, size; char *inverso; size = lenght(word); if (!(inverso = malloc(sizeof(char)*(size + 1)))){ printf("Falta de memória.\n"); exit(1); } for (i = 0; i < size; i++){ inverso[i] = word[size-i-1]; } return inverso; }
bool LoginScreen::init(){ stage = 0; icon = NULL; hasGetDownloadUrl = false; isTurn = false; // add "HelloWorld" splash screen" downSprite = MySprite::create("screens/login/bg.png"); downSprite->setPosition(ccp(Globe::SW/2, Globe::SH/2)); // add the sprite as a child to this layer this->addChild(downSprite, 1); CCSprite* pSprite1 = CCSprite::create("screens/login/info0.png"); pSprite1->setPosition(ccp(Globe::SW/2, Globe::SH/2+30)); pSprite1->setAnchorPoint(ccp(0.5,0)); this->addChild(pSprite1, 2); CCSprite* pSprite2 = CCSprite::create("screens/login/info1.png"); pSprite2->setPosition(ccp(Globe::SW/2, Globe::SH/2-30)); pSprite2->setAnchorPoint(ccp(0.5,1)); this->addChild(pSprite2, 2); int num = lenght(dian); int w = 40; float time = 3; for(int i = 0;i<num;i++){ dianOptin[i] =(num-i)*250/num; dian[i] = CCSprite::create("screens/login/dian.png"); int start = ((float)(num-1)/2)*w; dian[i]->setPosition(ccp(Globe::SW/2-start+i*w, Globe::SH/2)); dian[i]->setOpacity(dianOptin[i]); dian[i]->setScale(0.5+((float)dianOptin[i]/2)/250); this->addChild(dian[i], 3); } NetHander::getInfo(); frm = 0; showFrm = 0; isShowBack = false; return Screen::init(); }
int palindrome(char *word){ int i, size; size = lenght(word); size--; /*for (i = 0; i <= size/2; i++){ if (word [i] != word [size - i]){ return 0; } }*/ if (word[0] != word[size]){ return 0; } return 1; }
bool_t sorted(int a) { /** * @var Переменная для хранения текущего разряда числа. */ int curr; /** * @var Переменная для хранения предыдущего разряда числа. */ int prev; /** * @var Длина числа a. */ int l = lenght(a); /** * @var Число равное количество десятичных разрядов числа `a`. */ int p = ipow(10, l - 1); int i = 0; /* * Последовательно идем по разрядам числа, * и смотрим какой из них больше предыдущего. * Если есть хотя бы один такой (больше предыдущего), * то возвращаем `FALSE`. */ for (i = 0; l >= 2; ++i) { prev = (a / p) % 10; curr = ((a - prev * p) / (p / 10)) % 10; if (curr < prev) return FALSE; a = a - ((a / p) % 10) * p; p = p / 10; --l; } return TRUE; }
QVariant XmltvProgramme::data(int role) const { switch (role) { case DisplayRole: return display(); case DisplayIconRole: return displayIcon(); case TitleRole: return title(); case ChannelRole: return channelDisplayName(); case StartRole: return start(); case StopRole: return stop(); case SubTitleRole: return subTitle(); case DescRole: return desc(); case DateRole: return date(); case CategoryRole: return category(); case LanguageRole: return language(); case OriginalLanguageRole: return originalLanguage(); case LenghtRole: return lenght(); case LenghtUnitsRole: return lenghtUnits(); case IconRole: return icon(); case IconSizeRole: return iconSize(); default: return QVariant(); } }
static void init_game(t_sdl *game) { int i = 0; game->file = strdup("images/table7.png"); game->size[X] = 600; game->size[Y] = 600; if ((game->pos = malloc(sizeof(int) * lenght(game->philos) * 2)) == NULL) _error("init_game() : Malloc"); game->pos[i++] = 420; game->pos[i++] = 20; game->pos[i++] = 500; game->pos[i++] = 140; game->pos[i++] = 500; game->pos[i++] = 370; game->pos[i++] = 320; game->pos[i++] = 490; game->pos[i++] = 20; game->pos[i++] = 330; game->pos[i++] = 30; game->pos[i++] = 130; game->pos[i++] = 160; game->pos[i++] = 10; }
int lenght(t_list *list) { return (list->id > list->next->id) ? (1) : (1 + lenght(list->next)); }
Vector2<T> normalized( const Vector2<T>& a ) { return a * ( 1.0 / lenght( a ) ); }
int day1Interface() { cout << "\nOk man now you can choose the following operations:" << endl; cout << "'0' to perform mathematical operations" << endl; cout << "'1' for finding the intercept" << endl; cout << "'2' for calculating lenghts" << endl; cout << "'3' for calculating invariant masses" << endl; cout << "'4' for solving quadratic equations" << endl; int choice = SafeCinNum(); switch(choice) { case 0: { if(performMaths()) return 1; return 0; } case 1: { cout << "\n***********************\n\nGive me two points and I'll build a line out of them and find his intercept." << endl; double x1,y1,x2,y2; cout << "Give me the first point (x,y): \nx1 = "; x1 = SafeCinDouble(); cout << "\ny1 = "; y1 = SafeCinDouble(); cout << "\nGive me the second point (x,y): \nx2 = "; x2 = SafeCinDouble(); cout << "\ny2 = "; y2 = SafeCinDouble(); double m, q, x0; switch(findIntercept(x1, y1, x2, y2, m, q, x0)) { case -1: { cout << "Your line is x = " << x1 << "and its intercept on x ax is " << x1 << endl; break; } case -2: { cout << "Your line is y = " << y1 << " and has no intercept on x ax!" << endl; break; } default: cout << "Your line is y = " << m << "x + " << q << " and its intecept on x ax is: " << x0 << endl; } return 0; } case 2: { cout << "\n***********************\n\nI'll calculate the lenght of a vector. How many components has your vector?" << endl; vector < double > v; cout << "N components = "; int ncomp = SafeCinNum(); cout << "\nVery well, give me the components now (x1,x2,x3,...)!" << endl; for(int i = 0; i < ncomp; i++) { cout << "Component " << i+1 << ": " << endl; double curcomp = SafeCinDouble(); v.push_back(curcomp); } cout << "\nYour vector is: \n\n("; double length2 = 0; for(int i = 0; i < v.size(); i++) { if(i != (v.size()-1)) cout << v[i] << ","; } cout << ")\n" << endl; cout << "It's length is " << lenght(v) << endl; return 0; } case 3: { vector < double > E, px, py, pz; cout << "\n***********************\n\nI'll calculate the invatiant mass of N particles." << endl; cout << "How many particles do you want? N = "; int N = SafeCinNum(); for(int i = 0; i < N; i++) { cout << "\nGive me the 4-vector of particle " << i+1 << ":\nE = "; double val = SafeCinDouble(); if(val < 0) { cout << "Energy cannot be negative, retry." << endl; i--; continue; } E.push_back(val); cout << "\npx = "; val = SafeCinDouble(); px.push_back(val); cout << "\npy = "; val = SafeCinDouble(); py.push_back(val); cout << "\npz = "; val = SafeCinDouble(); pz.push_back(val); } double mm = invMass(E,px,py,pz); if(mm < 0) cout << "Etot is less then |ptot|, this is not physical!!!" << endl; else cout << "The invariant mass of your particles is: " << mm << endl; return 0; } case 4: { double a = 0, b = 0, c = 0; cout << "\n***********************\n\nThe equation to solve is ax^2 + bx + c = 0. Enter a, b and c" << endl; cout << "\na = "; a = SafeCinDouble(); cout << "\nb = "; b = SafeCinDouble(); cout << "\nc = "; c = SafeCinDouble(); double res1, res2; if( extractRoots(a,b,c,res1,res2) ) cout << "\nRoot are imaginary... sorry." << endl; else cout << "\nThe two roots are: " << res1 << " and " << res2 << endl; return 0; } default: return 1; } }
bool My_String::empty() const { return (lenght() == 0) ? 1 : 0; }
void buscar(char *word[], int count) { int chance, i, j, tam, teste, aux_lenght; char *aux, *comp; i = 0; chance = 0; if (count) { teste = 0; aux = word[i]; while (!teste && (i < count)) { if (aux[0] != '\0') { teste = 1; } aux = word[i]; i++; } if (teste) { chance = rand() % 2; } else { chance = 0; } } if (chance) { chance = rand() % count; aux = word[chance]; while (aux[0] == '\0') { chance = rand() % count; aux = word[chance]; } fprintf(fin,"b %s\n", aux); fprintf(fout, "v\n"); } else { //tam = MAX_PALAVRA; tam = rand() % MAX_PALAVRA; while(tam == 0) { tam = rand() % MAX_PALAVRA; } aux = malloc(sizeof(char)*(tam+1)); gerarPalavra(tam, aux); /* */ if (count > 0) { i = 0; while (i < count) { comp = word[i]; aux_lenght = lenght(aux); teste = 1; if (lenght(comp) == aux_lenght) { teste = 0; j = 0; while ((aux[j] != '\0') && (comp[j] != '\0') && !teste) { if (aux[j] == comp[j]) { j++; } else { teste = 1; } } } i++; if (!teste) { gerarPalavra(tam, aux); i = 0; } } } /* */ fprintf(fin,"b %s\n", aux); fprintf(fout, "f\n"); } }
void *largestPalindrome(node *T, char *word, int size, node *P){ int i, j, k, pos, test; char *largest, *aux_largest, *aux_word; node *pointer, *aux; P = Trie(); if (!(largest = malloc(sizeof(char)*size))){ printf("Falta de memória"); exit(1); } if (!(aux_largest = malloc(sizeof(char)*size))){ printf("Falta de memória"); exit(1); } if (!(aux_word = malloc(sizeof(char)*size))){ printf("Falta de memória"); exit(1); } largest[0] = '\0'; pointer = T; for (i = 0; i < size; i++){ aux = T; pos = position(word[i]); j = 0; k = i; while(aux->key[pos]){ aux_largest[j] = word[k]; j++; k++; aux = aux->key[pos]; pos = position(word[k]); } aux_largest[j] = '\0'; while (j > 0){ if (!palindrome(aux_largest)){ j--; aux_largest[j] = '\0'; } else { break; } } if (lenght(aux_largest) > lenght(largest)){ copy(largest, aux_largest); // largest = aux_largest /* Caso tenha uma palavra maior que anterior * limpar a trie para conter somente as maiores palíndromas */ emptyTree(P); } copy(aux_word, aux_largest); insert(P, aux_word); } printf("-- Maiores palindormas:"); printTree(P, lenght(largest)); }