void LDLQuadLine::reportQuadSplit(bool flat, const int q1, const int q2, const int q3, const int q4, const int t1, const int t2, const int t3, const int t4, const int t5, const int t6) { UCSTRING q1Str, q2Str, q3Str, q4Str; UCSTRING t1Str, t2Str, t3Str, t4Str, t5Str, t6Str; CUCSTR errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineConcave")); LDLErrorType errorType = LDLEConcaveQuad; if (!flat) { errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineNonFlat")); errorType = LDLENonFlatQuad; } q1Str = printPoint(q1); q2Str = printPoint(q2); q3Str = printPoint(q3); q4Str = printPoint(q4); t1Str = printPoint(t1); t2Str = printPoint(t2); t3Str = printPoint(t3); t4Str = printPoint(t4); t5Str = printPoint(t5); t6Str = printPoint(t6); setWarning(errorType, TCLocalStrings::get(_UC("LDLQuadLineSpit")), errorTypeString, q1Str.c_str(), q2Str.c_str(), q3Str.c_str(), q4Str.c_str(), t1Str.c_str(), t2Str.c_str(), t3Str.c_str(), t4Str.c_str(), t5Str.c_str(), t6Str.c_str()); }
void LDLQuadLine::reportBadVertexOrder(int index1, int index2, int index3, int index4) { UCSTRING oldStr[4]; UCSTRING newStr[4]; int indices[4]; int i; indices[0] = index1; indices[1] = index2; indices[2] = index3; indices[3] = index4; for (i = 0; i < 4; i++) { oldStr[i] = printPoint(i); newStr[i] = printPoint(indices[i]); } if (m_actionFlags.bfcClip) { setError(LDLEVertexOrder, TCLocalStrings::get(_UC("LDLQuadLineBfcBadVertSeq")), oldStr[0].c_str(), oldStr[1].c_str(), oldStr[2].c_str(), oldStr[3].c_str(), newStr[0].c_str(), newStr[1].c_str(), newStr[2].c_str(), newStr[3].c_str()); } else { setWarning(LDLEVertexOrder, TCLocalStrings::get(_UC("LDLQuadLineBadVertSeq")), oldStr[0].c_str(), oldStr[1].c_str(), oldStr[2].c_str(), oldStr[3].c_str(), newStr[0].c_str(), newStr[1].c_str(), newStr[2].c_str(), newStr[3].c_str()); } }
void LDLQuadLine::reportBadVertexOrder(int index1, int index2, int index3, int index4) { UCCHAR oldBuf[4][64]; UCCHAR newBuf[4][64]; int indices[4]; int i; indices[0] = index1; indices[1] = index2; indices[2] = index3; indices[3] = index4; for (i = 0; i < 4; i++) { printPoint(i, oldBuf[i]); printPoint(indices[i], newBuf[i]); } if (m_actionFlags.bfcClip) { setError(LDLEVertexOrder, TCLocalStrings::get(_UC("LDLQuadLineBfcBadVertSeq")), oldBuf[0], oldBuf[1], oldBuf[2], oldBuf[3], newBuf[0], newBuf[1], newBuf[2], newBuf[3]); } else { setWarning(LDLEVertexOrder, TCLocalStrings::get(_UC("LDLQuadLineBadVertSeq")), oldBuf[0], oldBuf[1], oldBuf[2], oldBuf[3], newBuf[0], newBuf[1], newBuf[2], newBuf[3]); } }
void LDLQuadLine::reportQuadSplit(bool flat, const int q1, const int q2, const int q3, const int q4, const int t1, const int t2, const int t3, const int t4, const int t5, const int t6) { UCCHAR q1Buf[64], q2Buf[64], q3Buf[64], q4Buf[64]; UCCHAR t1Buf[64], t2Buf[64], t3Buf[64], t4Buf[64], t5Buf[64], t6Buf[64]; CUCSTR errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineConcave")); LDLErrorType errorType = LDLEConcaveQuad; if (!flat) { errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineNonFlat")); errorType = LDLENonFlatQuad; } printPoint(q1, q1Buf); printPoint(q2, q2Buf); printPoint(q3, q3Buf); printPoint(q4, q4Buf); printPoint(t1, t1Buf); printPoint(t2, t2Buf); printPoint(t3, t3Buf); printPoint(t4, t4Buf); printPoint(t5, t5Buf); printPoint(t6, t6Buf); setWarning(errorType, TCLocalStrings::get(_UC("LDLQuadLineSpit")), errorTypeString, q1Buf, q2Buf, q3Buf, q4Buf, t1Buf, t2Buf, t3Buf, t4Buf, t5Buf, t6Buf); }
double findTwoPointsPath(const vector<DjiEdge >& allAroundObsEdgesPointer, DjiPoint ptStart, DjiPoint ptEnd, vector<DjiPoint>& path, bool isKeepStartEndPoint, bool isClearPath) { if (isSamePoint(ptStart, ptEnd)) { printPoint("ptStart", ptStart); printPoint("ptEnd", ptEnd); printLog("ptStart is same ptEnd, in findTwoPointsPath"); return 0; } vector<vector<DjiPoint> > pathPtsSeq; //求与障碍物边缘交点 for (int j = 0; j < (int)allAroundObsEdgesPointer.size(); j++) { addPathWihtAroundEdge(allAroundObsEdgesPointer[j], ptStart, ptEnd, pathPtsSeq); } //对pathPts 进行排序 sortPathsWithForwardVec(pathPtsSeq, ptEnd - ptStart); vector<DjiPoint> pathWayPts; pathWayPts.push_back(ptStart);//起点 for (int i = 0; i < (int)pathPtsSeq.size(); i++) { for (int j = 0; j < (int)pathPtsSeq[i].size(); j++) { pathWayPts.push_back(DjiPoint(pathPtsSeq[i][j].x, pathPtsSeq[i][j].y)); } } pathWayPts.push_back(ptEnd);//终点 if (pathWayPts.size() < 2) printLog("pathWayPts.size() < 2, in findPathFromTwoPts", true); double costDist= calPolylineDist(pathWayPts); if (!isKeepStartEndPoint) { pathWayPts.pop_back(); pathWayPts.erase(pathWayPts.begin()); } if (isClearPath) { path.clear(); } if (pathWayPts.size() > 0) { path.insert(path.end(), pathWayPts.begin(), pathWayPts.end()); } return costDist; }
int main(void) { struct point somewhere = { .x = 7, .y = 3 }; struct point other = { .x = 4, .y = 5 }; printPoint("Somewhere: ", somewhere); printPoint("Other: ", other); somewhere = translate(somewhere, other); printPoint("Somewhere translated by other", somewhere); return 0; }
void TextEdit::cursorPositionChanged() { //alignmentChanged(textEdit->alignment()); QColor col = Qt::red; QTextCharFormat fmt; fmt.setForeground(col); QTextCursor cursor = textEdit->textCursor(); cout<<"#TextEdit::cursorPositionChanged:"; cout<<"cursor.selectionStart:"<<cursor.selectionStart()<<","<<cursor.selectionEnd(); int selectionStart=cursor.selectionStart(), selectionEnd=cursor.selectionEnd(); cursor.mergeCharFormat(fmt); colorChanged(col); if(!cursor.hasSelection()) return; QTextBlock block=cursor.block(); int blockStart=block.position(); QTextLayout* layout=cursor.block().layout(); QTextLine layoutLine=layout->lineForTextPosition(selectionStart-blockStart); cout<<"layout line:"; int lineNumber= layoutLine.lineNumber(); QPoint blockOffset=layout->position().toPoint(); QPoint lineOffset=layoutLine.position().toPoint(); printPoint(blockOffset); printPoint(lineOffset); QPoint linePoint(blockOffset.x()+lineOffset.x(),blockOffset.y()+lineOffset.y()); QPoint lineEndPoint=QPoint(linePoint.x()+PAGEWIDTH,linePoint.y()); // cout<<"block:"<<rect.left()<<","<<rect.right()<<":"<<rect.top()<<","<<rect.bottom(); // cout<<"blockstart:"<<blockStart; // int x=blockPoint.x()+(float)((selectionStart-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH; // int y=blockPoint.y()+((selectionStart-blockStart)/LINELENGTH+1)*LINEHEIGHT; // int x1=blockPoint.x()+(float)((selectionEnd-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH; // cout<<"block position:"<<blockPoint.x()<<","<<blockPoint.y(); // cout<<"selection position:"<<x<<","<<y<<":"<<x1<<","<<y; //// int y1=blockPoint.y()+((cursor.selectionEnd()-blockStart)/LINELENGTH+1)*15; // QPoint selectionPoint(x,y); // QPoint selectionEndPoint(x1,y); image->paintLine(linePoint,lineEndPoint); // int lineStart=blockStart,lineEnd; // for(int i=0;i<block.lineCount();i++){ // QTextLine line = layout->lineAt(i); // qreal lineWidth=line.width(),lineHeight=line.height(); // lineEnd=lineStart+line.textLength(); // int a=line.textStart(),b=line.textLength()+a; // cout<<"line.cursorToX:"<<line.cursorToX(selectionStart)<<","<<line.cursorToX(selectionEnd); // cout<<"line.textstart:"<<a<<","<<b; // cout<<"line.width:"<<lineWidth<<" height:"<<lineHeight; // rect=line.naturalTextRect(); // cout<<"line.naturaltextrect:"<<rect.left()<<":"<<rect.top()<<":"<<rect.right()<<":"<<rect.bottom(); // lineStart=lineEnd; // } }
int main(){ struct point firstPoint = { .x = 7, .y = 3 }; struct point secondPoint = { .x = 35, .y = 39 }; printPoint("firstPoint is:", firstPoint); printPoint("secondPoint is:", secondPoint); translatePointer(&firstPoint, &secondPoint); printPointPointer("firstPoint translated by secondPoint", &firstPoint); printPoint("firstPoint translated by secondPoint", translate(firstPoint, secondPoint)); return 0; }
void printRotator(const rotator& r) { printf("----------------------\n"); for (int i = 0; i < DIMENSION; i++) { printPoint(r[i]); } printf("----------------------\n"); }
/** * Print a polygon to stdout in a human-readable way. This is done by * iterating through the points that make up the polygon and printing them. */ static void printPolygon(Polygon_t p, int n_points) { int i; for (i = 0; i < n_points; i++) printPoint(p.Points[i]); }
Point * findMidPoint(Point * a, Point *b){ Point * mid = malloc(sizeof(Point)); mid->x = (a->x + b->x)/2; mid->y = (a->y + b->y)/2; mid->z = (a->z + b->z)/2; printPoint("find mid point m" , mid); return mid; }
LDLTriangleLine *LDLQuadLine::newTriangleLine(int p1, int p2, int p3) { UCSTRING point1Str, point2Str, point3Str; char *newLine; LDLTriangleLine *retValue; std::basic_stringstream<UCSTRING::value_type> ss; point1Str = printPoint(p1); point2Str = printPoint(p2); point3Str = printPoint(p3); ss << "3 " << m_colorNumber << " " << point1Str << " " << point2Str << " " << point3Str; newLine = ucstringtombs(ss.str().c_str()); retValue = new LDLTriangleLine(m_parentModel, newLine, m_lineNumber, m_line); delete[] newLine; return retValue; }
int main() { srand((unsigned)time(NULL)); int N = 40000; int low = 0,high = N-1; PointList* L = newPointList(N); int i; for(i = 0; i < N; i++) { L->list[i].x = getRandomIndex(low,high)*67; } for(i = 0; i < N; i++) { L->list[i].x += getRandomIndex(low,high)*31; } for(i = 0; i < N; i++) { L->list[i].y = getRandomIndex(low,high)*73; } for(i = 0; i < N; i++) { L->list[i].y += getRandomIndex(low,high)*24; } //printPointList(L,N); printf("===============\n"); quickSort(L,low,high); //printPointList(L,N); PointClosed pointClosed; pointClosed.space = 60000; BruteForce(L,&pointClosed,0,N-1); printf("最近点为:a:"); printPoint(pointClosed.a); printf(" b:"); printPoint(pointClosed.b); printf(" 距离:%lf\n",pointClosed.space); PointClosed pointClosed_2; pointClosed_2.space = 60000; DivideAndConquer(L,&pointClosed_2,low,high); printf("最近点为:a:"); printPoint(pointClosed_2.a); printf(" b:"); printPoint(pointClosed_2.b); printf(" 距离:%lf\n",pointClosed_2.space); return 0; }
void printPointList(PointList* L,int N) { int i; for(i = 0; i < N; i++) { printPoint(&L->list[i]); printf("\n"); } }
LDLTriangleLine *LDLQuadLine::newTriangleLine(int p1, int p2, int p3) { UCCHAR pointBuf1[64] = _UC(""); UCCHAR pointBuf2[64] = _UC(""); UCCHAR pointBuf3[64] = _UC(""); UCCHAR ucNewLine[1024]; char *newLine; LDLTriangleLine *retValue; printPoint(p1, pointBuf1); printPoint(p2, pointBuf2); printPoint(p3, pointBuf3); sucprintf(ucNewLine, COUNT_OF(ucNewLine), _UC("3 %ld %s %s %s"), m_colorNumber, pointBuf1, pointBuf2, pointBuf3); newLine = ucstringtombs(ucNewLine); retValue = new LDLTriangleLine(m_parentModel, newLine, m_lineNumber, m_line); delete newLine; return retValue; }
int main(int argc, char const *argv[]){ readFile(); Point* pX = (Point*) malloc(count * sizeof(Point)); mergeSort(p,0,count-1, 1); printPoint(p); mergeSort(p,0,count-1, 0); setPoint(p, pX); printf("Co %d diem tren mat phang.\n", count); printPoint(p); // Timer ti; // bruteForce(p, count); // double y = ti.getElapsedTime(); // printf("Thoi gian chay: %f\n",y); // printf("Hai diem gan nhau nhat la:\nA(%d, %d), B(%d, %d)\n",a.x,a.y,b.x,b.y); float min = ClosestPair(pX, count); printf("Khoang cach gan nhat la: %f\n", min); printf("Hai diem gan nhau nhat la:\nA(%d, %d), B(%d, %d)\n",a.x,a.y,b.x,b.y); return 0; }
void printBeaconSystemConfiguration(OutputStream* outputStream) { Point* opponentPoint = getOpponentRobotPosition(); Laser* laser1 = getLaser(LASER_INDEX_1); Laser* laser2 = getLaser(LASER_INDEX_2); printLaserStruct(outputStream, laser1); println(outputStream); printLaserStruct(outputStream, laser2); appendCRLF(outputStream); // Last Detection Time appendStringAndDecf(outputStream, "lastDetectionTime=", getLastDetectionTimeInMillis()); println(outputStream); // Obsolete Detection Time Threshold appendStringAndDecf(outputStream, "obsoleteDetectionTimeThreshold=", getObsoleteDetectionTimeThreshold()); println(outputStream); // Notify Time Delay appendStringAndDecf(outputStream, "notifyTimeDelay=", getNotifyTimeDelay()); println(outputStream); // Opponent Position appendString(outputStream, "opponentPosition:"); printPoint(outputStream, opponentPoint, " mm"); // Distance between beacon appendStringAndDecf(outputStream, "distanceBetweenBeacon=", getDistanceBetweenBeacon()); appendString(outputStream, " mm"); println(outputStream); // Calibration Point appendString(outputStream, "calibrationPoint:"); printPoint(outputStream, &(beaconSystem.calibrationPoint), " mm"); // Opponent Position appendString(outputStream, "opponentPosition:"); printPoint(outputStream, opponentPoint, " mm"); }
Point * findUnitDirVector(Point * a, Point *b){ Point * n = malloc(sizeof(Point)); n->x = (a->x - b->x); n->y = (a->y - b->y); n->z = (a->z - b->z); int i = gcd(abs(n->x), gcd( abs(n->y),abs(n->z))); if( i != 1){ normalizeVector(n, i); } printPoint("find dir n" , n); return n; }
PPETask::PPETask(DjiPoint _startSprayingPosition,double _sprayingDirection, double _sprayingWidth, int _droneNum, bool _isUseCoordTransform) { if (!(_sprayingDirection <= 360 && _sprayingDirection >= 0 && _sprayingWidth>0 && _sprayingWidth<=MAX_SPRAY_WIDTH_METER)) { printLog("WaypointTask init input error", true); } if (_isUseCoordTransform) { if (!isLegalLatLong(_startSprayingPosition)) { printLog("_startSprayingPosition is illegal LatLong", true); } } if (_droneNum<1) { printLog("inupt error droneNum<1", true); } isUseCoordTransform = _isUseCoordTransform; //all the latitude_longtitude data will be transformed into plane coordinate (the unit is metre) tran = isUseCoordTransform ? CoordTransform(_startSprayingPosition) : CoordTransform(); homePoint = isUseCoordTransform ? tran.latlong2plane(_startSprayingPosition) : _startSprayingPosition; droneNum = _droneNum; forwardVec = CoordTransform::dirSouthEastFromNorthAngle(_sprayingDirection); forwardVec = forwardVec / molMat(forwardVec); //rotate clockwise 90 degree sideVec.x = forwardVec.y; sideVec.y = -forwardVec.x; sprayWidth = _sprayingWidth; printLog(" "); printPoint("startSprayingPosition: ", _startSprayingPosition); printLog("sprayingDirection: " + double2string(_sprayingDirection)); printLog("sprayingWidth: " + double2string(sprayWidth)); printLog("droneNum: " + int2string(droneNum)); initDefaultValues(); }
main() { Point pt1 = makepoint(1, 2); Point pt2; pt2.x = 3; pt2.y = 4; Rect rec; rec.pt1 = pt1; rec.pt2 = pt2; printPoint(pt1); double sqr = sqrt((double)pt1.x * pt1.x + (double)pt1.y * pt1.y); printf("%f\n", dist(pt1)); printf("%d\n", ptinrect(addpoint(pt1, pt2), rec)); printf("%d\n", ptinrect(pt1, rec)); }
LDLFileLineArray *LDLQuadLine::removeMatchingPoint(void) { LDLFileLineArray *fileLineArray = removePoint(m_matchingIndex); if (fileLineArray) { UCSTRING pointStr; pointStr = printPoint(m_matchingIndex); setWarning(LDLEMatchingPoints, TCLocalStrings::get(_UC("LDLQuadLineIdentical")), m_matchingIndex + 1, pointStr.c_str()); } else { setError(LDLEGeneral, TCLocalStrings::get(_UC("LDLQuadLineIdenticalError"))); } return fileLineArray; }
LDLFileLineArray *LDLQuadLine::removeMatchingPoint(void) { LDLFileLineArray *fileLineArray = removePoint(m_matchingIndex); if (fileLineArray) { UCCHAR pointBuf[64] = _UC(""); printPoint(m_matchingIndex, pointBuf); setWarning(LDLEMatchingPoints, TCLocalStrings::get(_UC("LDLQuadLineIdentical")), m_matchingIndex + 1, pointBuf); } else { setError(LDLEGeneral, TCLocalStrings::get(_UC("LDLQuadLineIdenticalError"))); } return fileLineArray; }
void adjustAntiClockWise(DjiEdge * edge){ deleteCollinearPoint(edge->edge); deleteClosedPoint(edge->edge, MIN_DIST_TO_DELETE); if (isSelfIntersect(edge->edge)) printLog("error isSelfIntersect, in dataPreHandle", true); if (!isAntiClockwise(edge->edge)) { edge->edge = reversePoints(edge->edge); if (!isAntiClockwise(edge->edge)) { printLog("edge points size= " + int2string(edge->edge.size())); for (int j = 0; j < edge->edge.size(); j++) { printPoint(int2string(j), edge->edge[j]); } printLog("edge not anti-clockwise or clockwise, in dataPreHandle", true); } } }
void printPosition(OutputStream* outputStream) { // clearScreen(); appendCRLF(outputStream); Position* p = getPosition(); appendStringAndDec(outputStream, "left=", getCoderValue(CODER_LEFT)); appendStringAndDec(outputStream, " | right=", getCoderValue(CODER_RIGHT)); println(outputStream); printPoint(outputStream, &(p->pos), " mm"); appendStringAndAngleInDeg(outputStream, "ang:", p->orientation); appendStringAndAngleInDeg(outputStream, "\r\nang init:", p->initialOrientation); appendStringAndDecf(outputStream, "\r\nlastLeft:", lastLeft); appendString(outputStream, " pulse"); appendStringAndDecf(outputStream, "\r\nlastRight:", lastRight); appendString(outputStream, " pulse"); appendStringAndAngleInDeg(outputStream, "\r\nlastAng:", lastAngle); println(outputStream); }
void printGameStrategyContext(OutputStream* outputStream, GameStrategyContext* context) { appendString(outputStream, "GameStrategyContext\n"); appendString(outputStream, "\tstrategy.name="); // gameStrategy if (context->gameStrategy != NULL) { appendString(outputStream, context->gameStrategy->name); } else { appendString(outputStream, "NULL"); } // elapsedMatchTime appendStringAndDecf(outputStream, "\n\telapsedMatchTime=", context->elapsedMatchTime); println(outputStream); // Robot Position appendString(outputStream, "\trobotPosition="); printPoint(outputStream, &(context->robotPosition), ""); appendStringAndDec(outputStream, "\n\trobotAngle (ddeg)=", context->robotAngle); // nearestLocation appendString(outputStream, "\n\tnearestLocation="); if (context->nearestLocation != NULL) { printLocation(outputStream, context->nearestLocation); } else { appendString(outputStream, "NULL"); } appendStringAndDec(outputStream, "\ntimeSinceLastCollision=", context->timeSinceLastCollision); // Robot Position appendString(outputStream, "\n\topponentRobotPosition="); printPoint(outputStream, &(context->opponentRobotPosition), ""); // Obstacle Position appendString(outputStream, "\n\tlastObstaclePosition="); printPoint(outputStream, &(context->lastObstaclePosition), ""); // current Target appendString(outputStream, "\n\tcurrentTarget="); if (context->currentTarget != NULL) { printGameTarget(outputStream, context->currentTarget, false); } else { appendString(outputStream, "NULL"); } // currentTrajectory if (&(context->currentTrajectory) != NULL) { printLocationList(outputStream, "\n\tcurrentTrajectory:", &(context->currentTrajectory)); } else { appendString(outputStream, "\n\tcurrentTrajectory=NULL"); } appendStringAndDec(outputStream, "\n\tteamColor=", context->color); appendStringAndDec(outputStream, "\n\tstrategyIndex=", context->strategyIndex); appendStringAndDec(outputStream, "\n\tmaxTargetToHandle=", context->maxTargetToHandle); // appendStringAndDec(outputStream, "\n\tmustDoNextStep=", context->mustDoNextStep); appendStringAndDec(outputStream, "\n\thasMoreNextSteps=", context->hasMoreNextSteps); println(outputStream); }
int main(int argc, char ** argv) { if (argc <= 3) usage(argv[0]); char * benchmark = argv[1]; int num_keys = atoi(argv[2]); int value = 0; int i; SETUP interval = atoi(argv[3]); startTime = get_time(); startData = get_data_mem(); if (!strcmp(benchmark, "sequential")) { for(i = 0; i < num_keys; i++) { INSERT_INT_INTO_HASH(i, value); printPoint(i); } } else if (!strcmp(benchmark, "random")) { srandom(1); // for a fair/deterministic comparison for(i = 0; i < num_keys; i++) { INSERT_INT_INTO_HASH((int)random(), value); printPoint(i); } } else if (!strcmp(benchmark, "delete")) { for(i = 0; i < num_keys; i++) INSERT_INT_INTO_HASH(i, value); startTime = get_time(); for(i = 0; i < num_keys; i++) { DELETE_INT_FROM_HASH(i); printPoint(i); } } else if (!strcmp(benchmark, "sequentialstring")) { for(i = 0; i < num_keys; i++) { INSERT_STR_INTO_HASH(new_string_from_integer(i), value); printPoint(i); } } else if (!strcmp(benchmark, "randomstring")) { srandom(1); // for a fair/deterministic comparison for(i = 0; i < num_keys; i++) { INSERT_STR_INTO_HASH(new_string_from_integer((int)random()), value); printPoint(i); } } else if (!strcmp(benchmark, "deletestring")) { for(i = 0; i < num_keys; i++) INSERT_STR_INTO_HASH(new_string_from_integer(i), value); startTime = get_time(); for(i = 0; i < num_keys; i++) { DELETE_STR_FROM_HASH(new_string_from_integer(i)); printPoint(i); } } /* This benchmark counts the number of distinct words (strings on nonspace characters) in the king james bible. */ else if (!strcmp(benchmark, "kjvmark")) { const char * file = "data/king-james-bible.txt"; if (argc >= 5 && strcmp(argv[3], "-f") == 0) file = argv[4]; size_t size = filesize(file); char * text = (char *)malloc(size + 1); // + 1 allows '\0' termination of last word int fd; if ((fd = open(file, O_RDONLY)) < 0) { fprintf(stderr, "%s: Failed to open %s\n", argv[0], file); exit(1); } if (read(fd, text, size) != size) { fprintf(stderr, "%s: Failed to read %lu bytes from %s\n", argv[0], size, file); exit(1); } // Reset start time and memory now that preparations are done startTime = get_time(); startData = get_data_mem(); size_t start = 0; for (;;) { while (start < size && isspace(text[start])) start++; if (start == size) break; size_t endWord = start + 1; while (endWord < size && !isspace(text[endWord])) endWord++; text[endWord] = '\0'; // '\0' terminate the "word" (actually a space delimitted sequence) INSERT_STR_INTO_HASH(&text[start], value); start = endWord + 1; } if (STR_HASH_GET_SIZE() != 34027) { fprintf(stderr, "%s: Incorrect number of pseudo words were found in the KJV text (expected 34027, got %lu)\n", argv[0], STR_HASH_GET_SIZE()); exit(1); } printPoint(-1); // -1 forces printing } else { fprintf(stderr, "%s: No such benchmark '%s'", argv[0], benchmark); usage(argv[0]); } }
void BiGraph::print() { printPoint(); printEdge(); };
void printPoints(const vector<point> &points) { DEBUG; for (unsigned int i = 0; i < points.size(); i++) { printPoint(points[i]); } }
int main() { char R[7],*p; long long ans[50]; int i,plength,pindex,length,n,numlength,ppindex,endindex,temp; while(scanf("%s%d",R,&n)!=-1) { if(n==0) { printf("1\n"); continue; } length = strlen(R); if(length == 0 && R[0] == '0' && n == 1) { printf("1\n"); continue; } p = strchr(R,'.'); if(p == NULL) pindex = length; else pindex = p - R; plength = (length - pindex - 1) * n; for(i = 0 ; i < 50; i ++) ans[i] = 0l; length = cal(R,n,ans); numlength = length * 4; ///如果小数点的格式是.xxxxxx .001 if(plength >= numlength + getLength(ans[length])) { endindex = chechEnd(ans,length); printf("."); temp = plength - numlength - getLength(ans[length]); for(i = 0 ; i < temp; i ++) printf("0"); if(endindex == length) { temp = (int) ans[length]; while(temp%10 == 0) temp/=10; printf("%d\n",temp); } else { for(i = length - 1; i > endindex; i --) printf("%04ld",ans[i]); printEnd(ans[endindex]); } } else { ///如果小数点是xxxx. if(plength == 0) { printf("%ld",ans[length]); for(i = length - 1; i >= 0; i --) printf("%04ld",ans[i]); printf("\n"); } else { ///如果小数点是xxxx.xxxx pindex = plength % 4; ppindex = plength /4; endindex = chechEnd(ans,length); temp = (endindex>ppindex?ppindex:endindex); for(i = length; i > temp; i --) { if(ppindex == i) { if(i == length) printPoint(ans[i],pindex,'h'); else printPoint(ans[i],pindex,'m'); } else { if(i == length) printf("%ld",ans[i]); else printf("%04ld",ans[i]); } } ///如果小数点xxxx000.,XXXX000.01 if(ppindex < endindex) { if(pindex == 0) printf("0000\n"); if(pindex == 1) printf("000\n"); else if(pindex == 2) printf("00\n"); else if(pindex == 3) printf("0\n"); } else if(ppindex == endindex) { if(pindex == 0) printf("%04ld\n",ans[endindex]); else { printPoint(ans[endindex],pindex,'m'); printf("\n"); } } else printEnd(ans[endindex]); } } } return 0; }