Pattern *Pattern::create(string pLineFrameFile){ Pattern *ret = new Pattern(); if(ret && ret->init(pLineFrameFile)){ ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
void initX(int argc, char* argv[], XInfo& xinfo) { XSizeHints hints; unsigned long background, foreground; /* * Display opening uses the DISPLAY environment variable. * It can go wrong if DISPLAY isn't set, or you don't have permission. */ xinfo.display = XOpenDisplay( "" ); if ( !xinfo.display ) { error( "Can't open display." ); } /* * Find out some things about the display you're using. */ xinfo.screen = DefaultScreen( xinfo.display ); foreground = WhitePixel( xinfo.display, xinfo.screen ); background = BlackPixel( xinfo.display, xinfo.screen ); /* * Set up hints and properties for the window manager, and open a window. * Arguments to XCreateSimpleWindow : * display - the display on which the window is opened * parent - the parent of the window in the window tree * x,y - the position of the upper left corner * width, height - the size of the window * Border - the width of the window border * foreground - the colour of the window border * background - the colour of the window background. * Arguments to XSetStandardProperties : * display - the display on which the window exists * window - the window whose properties are set * Hello1 - the title of the window * Hello2 - the title of the icon * none - a pixmap for the icon * argv, argc - a comand to run in the window * hints - sizes to use for the window. */ hints.x = 100; hints.y = 100; hints.width = 800; hints.height = 600; hints.flags = PPosition | PSize; xinfo.window = XCreateSimpleWindow( xinfo.display, DefaultRootWindow( xinfo.display ), hints.x, hints.y, hints.width, hints.height, Border, foreground, background ); XSetStandardProperties( xinfo.display, xinfo.window, "Lunar Landing", "Lunar Landing", None, argv, argc, &hints ); //initiate all the terrain and pattern. pattern.init(3, (int)hints.width, (int)hints.height,4); /* * Get a graphics context and set the drawing colours. * Arguments to XCreateGC * display - which uses this GC * window - which uses this GC * GCflags - flags which determine which parts of the GC are used * GCdata - a struct that fills in GC data at initialization. */ int i = 0; xinfo.gc[i] = XCreateGC(xinfo.display, xinfo.window, 0, 0); XSetForeground(xinfo.display, xinfo.gc[i], BlackPixel(xinfo.display, xinfo.screen)); XSetBackground(xinfo.display, xinfo.gc[i], WhitePixel(xinfo.display, xinfo.screen)); XSetFillStyle(xinfo.display, xinfo.gc[i], FillSolid); XSetLineAttributes(xinfo.display, xinfo.gc[i], 1, LineSolid, CapButt, JoinRound); // Reverse Video i = 1; xinfo.gc[i] = XCreateGC(xinfo.display, xinfo.window, 0, 0); XSetForeground(xinfo.display, xinfo.gc[i], WhitePixel(xinfo.display, xinfo.screen)); XSetBackground(xinfo.display, xinfo.gc[i], BlackPixel(xinfo.display, xinfo.screen)); XSetFillStyle(xinfo.display, xinfo.gc[i], FillSolid); XSetLineAttributes(xinfo.display, xinfo.gc[i], 1, LineSolid, CapButt, JoinRound); int depth = DefaultDepth(xinfo.display, DefaultScreen(xinfo.display)); xinfo.pixmap = XCreatePixmap(xinfo.display, xinfo.window, hints.width, hints.height, depth); xinfo.width = hints.width; xinfo.height = hints.height; // Tell the window manager what input events you want. // XSelectInput( xinfo.display, xinfo.window, KeyPressMask); /* * Put the window on the screen. */ XMapRaised( xinfo.display, xinfo.window ); XFlush(xinfo.display); sleep(2); // let server get set up before sending drawing commands }
int main (void) { #ifndef ONLINE_JUDGE freopen ("T1257.in", "r", stdin); freopen ("T1257.out", "w", stdout); #endif scanf ("%d", &n); getline (cin, line); solve.init(n); for (int i=0; i<n; ++i){ getline (cin, line); solve.addPattern(line); } while (getline (cin, line)){ ans.clear(); ans.reserve(2*line.size()); int beg_line=0; int beg_word=-1; bool inword=false; for (int i=0; i<line.size(); ++i){ if (!inword && isalpha(line[i])){ inword=true; beg_word=i; } else if (inword && !isalpha(line[i])){ inword=false; beg_word=-1; } if (i-beg_line==39){ // work if(!inword){ ans+=line.substr(beg_line, 40)+"\n"; beg_line=i+1; } else{ int end_word=i; while (end_word<line.size() && isalpha(line[end_word])) ++end_word; if (i==end_word-1){ ans+=line.substr(beg_line, end_word-beg_line); beg_line=end_word; if (end_word<line.size()) ans+="\n"; } else{ int len=i-beg_word; i=end_word-1; ans+=line.substr(beg_line, beg_word-beg_line); string word = line.substr(beg_word, end_word-beg_word); int w = solve.find (word, len); if (w==-1){ ans+="\n"/*+word*/; beg_line=beg_word; } else{ ans+=word.substr(0, w)+"-\n"/*+word.substr(w)*/; beg_line=beg_word+w; } } inword=false; beg_word=-1; } } // end for } if (beg_line<line.size()){ ans+=line.substr(beg_line); } cout << ans << "\n"; // end while } return 0; }