PEARSON
[]Jon Bentley Programming Pearls Second Edition
CIP /Bentley,J.).--2.--2015.1 Programming pearls,second edition ISBN978-7-115-35761-8 ....TP311.1 CIP2014266600 Jon Bentley []Jon Bentley 100164315@ptpress.com.cn http://www.ptpress.com.cn 7209601/16 17.5 320201512 1-6000201511 01-2006-7038 39.00 (010)81055410(010)81055316 (010)81055315 0021
Authorized translation from the English language edition,entitled Programming Pearls,Second Edition,0201657880 by Jon Bentley,published by Pearson Education,Inc.,publishing as Addison Wesley,Copyright 2000 by Lucent Technologies. All rights reserved.No part of this book may be reproduced or transmitted in any form or by any means,electronic or mechanical,including photocopying,recording or by any information storage retrieval system,without permission from Pearson Education,Inc. CHINESE SIMPLIFIED language edition published by PEARSON EDUCATION ASIA LTD.and POSTS & TELECOM PRESS Copyright 2015. Pearson Education Asia Ltd. Pearson Education
Jon Bentley2070ACMCommunications of the ACMACM19861988Programming PearlsMore Programming Pearls22000C C++ Java AwkC
Fred BrooksSteve McConnell ACM 19861113123 C++ A 1 http://netlib.bell-labs.com/cm/cs/pearls/ CC++for i = [0,n)0n-1i for function(i,j)ijarray[i,j] 128 MBWindows NT 4.0400 MHz Pentium II 145111121311364 KB13.81514125% Peter DenningStuart LynnACMPeterACMACMRoz SteierNancy AdrianceACMACM Al AhoPeter DenningMike GareyDavid JohnsonBrian KernighanJohn LindermanDoug McIlroyDon StanatHenry BairdBill ClevelandDavid GriesEric GrosseLynn JelinskiSteve JohnsonBob MelvilleBob MartinArno PenziasMarilyn RoperChris Van WykVic VyssotskyPamela ZaveAl AhoAndrew HumeBrian KernighanRavi SethiLaura SkingerBjarne StroustrupEF 485 Dan BentleyRuss CoxBrian KernighanMark KernighanJohn LindermanSteve McConnellDoug McIlroyRob PikeHoward TrickeyChris Van WykPaul AbrahamsGlenda ChildressEric GrosseAnn MartinPeter McIlroyPeter MemishianSundar NarasimhanLisa RickerDennis RitchieRavi SethiCarol SmithTom SzymanskiKentaro ToyamaAddison-WesleyPeter Gordon Jon Bentley Murray Hill 198512 19998
EFEngineering Fundamentals
4911145 2 !
1 MB 37800
n n n=10 1 MB10
71 MB143 000321 MB250 000400249 999250 000 250 000499 999409 750 0009 999 99920 1140
1 MB8001 000
20 20 {1,2,3,5,8,13} 0 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 71 0001 000ii120051 MB 011n10 000 000 /* phase 1: initialize set to empty */ for i = [0,n) bit[i] = 0 /* phase 2: insert present elements into the set */ for each i in the input file bit[i] = 1 /* phase 3: write sorted output */ for i = [0,n) if bit[i] == 1 write i on the output file for i=[0,n)0n-1i
10 3 Chuck Yeager 90%101112 1.3405 Antoine de Saint-Exupry 12.4
3.1n10 000 0001 000 000 4.3nkk0n-1k 5.1 MB1.25 MB1 MB 6.10 7.[R.Weil]1.4n 8.8008008778881 MB 9.0 11.2080CAD40100 12.NASA100
Michael Jackson Software Requirements & Specifications Addison-Wesley 1995 James L.AdamsConceptuel Blockbusting3Perseus1986Adams101112
!Martin Gardner
A.403232 B.n in=8i=3abcdefghdefghabcnnn? C.potsstoptops
110050751nlog nn1 00010n10020
nn/2log nACMTWA Reservation System 1100CPU0.3 Roy Weil 1000 Weil10 A4032322324 294 967 2961536 870 9128 Ed Reingold 11.9
Bnxni xiniiixixni x[0]tx[i]x[0]x[2i]x[i]xnx[0]ti3n12
x[1]3 xabbaaxiabbb l b r b r aab r ab l b r b r b l aab3GriesMills abbaabaa r bba r b r (a r b r ) r baabcdefgh reverse(0,i-1)/* cbadefgh */ reverse(i,n-1)/* cbahgfed */ reverse(0,n-1)/* defghabc */ Doug McIlroy 5
Brian Kernighan 1971
Cdepositdopiestpositedtopside6 cholecystoduodenostomyduodenocholecystostomy2222! 1.124 10 1.1 10 7.11.1 10 230 0001 230 000 230 000/ 1/=52 900 10 =52 90014.7 depositdeiopstdopiestTom Cargill2.8
mississippii4m1p2s41i4mp2s4 26 Soundex
Knuth 6Soundex
2.4 300 000 00032 3.in 4.n 5.abbaabccba 6.2070
Mike Lesk LESK*M*5375*6* Lesk Lesk0.2% 7.2060Vic Vyssotsky4 0004 00050Vyssotsky 8.[J.Ullman]ntkkt 9.n 10.150 cm 155
8.8
Csign100 int charcomp(char *x,char *y) { return *x - *y;} #define WORDMAX 100 int main(void) { char word[WORDMAX],sig[WORDMAX]; while (scanf("%s",word) !=EOF) { strcpy(sig,word); qsort(sig,strlen(sig),sizeof(char),charcomp); printf("%s %s\n",sig,word); } return 0; } whilewordstrcpysigCqsortsigprintf sortsquash int main(void) { char word[WORDMAX],sig[WORDMAX],oldsig[WORDMAX]; int linenum = 0; strcpy(oldsig,""); while (scanf("%s %s",sig,word) != EOF) { if (strcmp(oldsig,sig) !=0 && linenum >0) printf("\n"); strcpy(oldsig,sig); linenum++; printf("%s ",word); } printf("\n"); return 0; } printfifsigoldsigprintf sign gramlist dictionarysignsignsortsortsquashsquashgramlist18sign4sort11squash3 230 000-s-ed subessential suitableness canter creant cretan nectar recant tanrec trance caret carte cater crate creat creta react recta trace destain instead sainted satined adroitly dilatory idolatry least setal slate stale steal stela tales reins resin rinse risen serin siren constitutionalism misconstitutional
if (k == 1) c001++ if (k == 2) c002++ ... if (k == 500) c500++ 1500 1 000500500
6258300710228 10003502572
150803040 2.51.7James Adams 8540 ethnicgroup = entry[0] campus = entry[1] if entry[2] == refused declined[ethnicgroup,2]++ else j = 1 + entry[2] count[campus,ethnicgroup,j]++ if entry[3] == refused declined[ethnicgroup,3]++ else j = 4 + entry[3] count[campus,ethnicgroup,j]++ offset 0,0,1,4,6,640 for i = [2,8] if entry[i] == refused declined[ethnicgroup,i]++ else j = offset[i] + entry[i] count[campus,ethnicgroup,j]++
Welcome back,Jane! We hope that you and all the members of the Public family are constantly reminding your neighbors there on Maple Street to shop with us.
Next page