practice of programming

Learn about practice of programming, we have the largest and most updated practice of programming information on alibabacloud.com

C + + Programming Practice Guide 1.13 Finding composite rewriting requirements in natural number set implementation

Rewrite requirement 1: Implemented with single-linked listOverwrite Requirement 2: Delete the linked list node in turn in the destructor#include #includeusing namespacestd;structlinknode{intdata; Linknode*next;};classnoprime{friendstructLinknode; Linknode*Head; intN; Public: Noprime (intN1) {N=N1; } voidcreat (); intYesintx) { for(intI=2; i2; i++) if(x%i==0) return 1; return 0; } voidSearch (); voidprint () {Linknode* p=head->Next;

C + + Programming Practice Guide 1.9 statistics and substitution of keyword rewriting requirements in a string implementation

::findkeywords (stringKey[],stringSwapkey[],intLen) { intI=Len; stringtemp; Temp=p; intPos=temp.find (key[i-1]); while(i) { while(pos!=-1) {temp.replace (pos,key[i-1].length (), swapkey[i-1]); POS=temp.find (key[i-1]); } I--; } memset (P,0,sizeof(p)); strcpy (P,temp.c_str ());}voidwordnum::p rocess () {intword=1; intLen; Len=strlen (P); Char* r=New Char[Strlen (P)]; strcpy (R,P); for(intI=0; i) { if(((r[i]>='a'r[i]'Z')|| (r[i]>='A'r[i]'Z')) word) {C++; Word=0; }

C + + Programming Practice Guide 1.14 string cross-insert rewrite requirements implementation

#include #include #include using namespace Std;Class STRING{Char *str1;Char *str2;PublicSTRING (char* s1,char* S2){Str1=new Char[strlen (S1)];Str2=new Char[strlen (S2)];strcpy (STR1,S1);strcpy (STR2,S2);}void Insertinorder ();void process ();void print (){cout}};void STRING::p rocess (){int len1,len2,count=1;Char str[80];int i,j=0,k=0;Len1=strlen (STR1);Len2=strlen (STR2);int n=len2/len1;for (i=0;i{if (count% (n+1) ==0){Str[i]=str1[j++];count++;}else{Str[i]=str2[k++];count++;}}str[i]= ' + ';cout

Linux reliable/unreliable signal programming practice

]:~$ ulimit-acore File size (blocks,-c) unlimiteddata seg size (Kbytes,-D) unlimitedscheduling Priority (-e) 0file size (blocks,-f) unlimitedpending signals (-I ) 47131max locked memory (Kbytes, L) 64max Memory Size (Kbytes,-m) unlimitedopen files (-N) 1024pipe size (bytes,-p) 8POSIX message Queues (bytes,-Q) 819200real-time priority (-R) 0stack size (Kbytes,-s

Practice of multithreading Classic programming problems

Title One: Write two threads, one thread prints 1~52, another thread prints the letter a~z. The print order is 12a34b56c ..... 5152Z. Requires the use of communication between threads. Package test;Import Java.lang.Thread;Class printer{private int index = 1;Public synchronized void print (int n) {while (index%3==0) {try{Wait ();/* The Notify method that calls this object in other threads money, causing the current thread to wait */}catch (Exception e){E.printstacktrace ();}}System.out.print (ind

Hand in your homework-python programming (from Get started to practice)

The 4th chapter is the exercise in the Operation list 4.3.(1) Create a list that contains integers within the 3~30 that can be divisible by 2, and then use a for loop to hit the numbers in the list.(2) Create a list that contains the first 10 integers, and then use a for loop to print the list.(3) Use list resolution to generate a list that contains the first 10 integers of the cube.#注意里面的range噢 ~Specific answers:(1)(2) and (3), the first use of the list to parse, because relatively neat.Hand in

Java Threading and concurrency programming Practice----synchronizer (countdown latch)

{finalstaticintnthreads =3;publicstaticvoidmain (String[]args) {finalcountdownlatch startsignal=newcountdownlatch (1); finalcountdownlatchdonesignal= newcountdownlatch (nthreads); Runnabler=newrunnable () {@Overridepublic voidrun () {try{ System.out.println (Thread.CurrentThread (). GetName () + "Enter Wait"); startsignal.await (); System.out.println (Thread.CurrentThread (). GetName () + "Start performing tasks"); Thread.Sleep ($);d onesignal.countdown ();} catch (interruptedexceptione) {e.prin

"Python Core programming (third Edition)" 1th chapter Regular Expression practice answer __ storage

has been a programmer for many years, the first time to open a blog, welcome to fellow critics, comments.Recently obsessed with Python, after reading the Python Basics tutorial, and holding a "Python Core programming (third edition)" began to chew.After reading the first chapter, found a lot of very good exercises, I tried to do some, but on the internet can not find a very good answer. So decided to write their own write a record of their answers, ea

The practice of Shell programming is genuine (code example)

x+ matches 1 or more x strings, but matches the minimum possible number of times . * matches any character 0 or one time . + Match any character 1 or more times {m} matches exactly a specified string of M {M,n} matches a specified string below M + N [] matches the characters in [] [^] matches characters that do not match [] [0-9] match all numeric characters [A-z] matches all lowercase letters ^ characters that match the beginning of a character $ matches characters ending

Java Concurrency Programming Practice (Reading Notes) task execution (not finished)

data:imagedatas) {renderimage (data);//working with pictures } } Catch(Interruptedexception |executionexception e) { //TODO auto-generated Catch blockE.printstacktrace (); } }}This execution strategy still has limitations, because running heterogeneous tasks in parallel does not get good performance. Only a large number of independent and homogeneous tasks can be processed concurrently to achieve real performance gains.3. Third Way: Using the Completionservice pa

PKU C + + programming Practice Learning Note 4 operator overloading

requirements? Normal functions, and cannot access private members of a class Class complex{ double Real, imag; Public: Complex (Double R, double i): Real (R), Imag (i) {}; Complex operator+ (Double r);}; Complex complex::operator+ (Double R) {//can interpret c+5 return Complex (real + R, imag);}After the above overloads:Complex C;c = C + 5; There is a definition, equivalent to C = C.operator + (5);But:c = 5 + C; Compilation errorTo make the above expression possible, the + overl

C + + Programming practice Guidance 1.5 for two integer set merge set rewrite requirements implementation

=NewLinknode; Newlinknode->next=NULL; Newlinknode->data=q->data; T->next=Newlinknode; T=Newlinknode; } q=q->Next; } returnHead;}intMainintargcChar*argv[]) { ints1[]={1,3,5,7,9}; ints2[]={1,2,3,4,5,6}; Linknode* ahead,*bhead,*chead,*Head; SETSet; AHead=Set. creat (S1,sizeof(S1)/sizeof(s1[0])); Bhead=Set. creat (S2,sizeof(S2)/sizeof(s2[0])); Chead=Set. Copy (AHead); Head=Set. Insert (Bhead,chead); Set. Output (Head); System ("PAUSE"); returnexit_success;}C + +

C + + Programming Practice Guide 1.4 positive integer conversion to string rewrite requirements implementation

Rewrite requirements 1: Change to be suitable for processing super-long integers#include #include#includestring>using namespacestd;structlinknode{ Short intdata; Linknode*next;};classstr{stringstr; Public: STR (stringx) {str=x; } structlinknode*itoa (); structlinknode* Reverse (linknode*phead); voidPrint (linknode*phead) {Linknode* p=Phead; P=p->Next; cout"n="; while(p) {coutdata; P=p->Next; } coutEndl; }};structlinknode*Str::itoa () {Linknode* phead=NewLinknode; Phead->next=NULL;

Interview Enterprise Shell programming basic problem Solving practice (pro-Test)

://s3.51cto.com/wyfs02/M00/84/4D/wKioL1eMbpmAz3j8AAA2tkJ28Po115.jpg-wh_500x0-wm_3 -wmp_4-s_3298491014.jpg "style=" Float:none; "title=" psb5.jpg "alt=" Wkiol1embpmaz3j8aaa2tkj28po115.jpg-wh_50 "/> method: Vim zhong333.sh #!/bin/bashread-p "Pleaseenteranumber : "nfor ((x=1;x5. Use shell or Python to write a right-angled trapezoid program that receives user input parameters N,mFor example: implemented with the * number (zhong4.sh)650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/4D

Linux interprocess communication (IPC) programming Practice (11) System v Semaphore---Implement a first in, out shared memory Shmfifo

**/ //obtains the readout position from the structure char *index = p_payload + (P_shm->rd_index * p_shm->blksize); Read memcpy (buf, index, p_shm->blksize); P_shm->rd_index = (p_shm->rd_index+1)%p_shm->blocks; /** exit Critical Zone **/ Sem_v (Sem_mutex); Sem_v (Sem_full); } . Phony:clean all CC = g++ cppflags =-wall-g bin = Write Read free SOURCES = $ (bin.=.cpp) All : $ (BIN) %.O:%.cpp $ (cc) $ (cppflags)-C $^-o [ema

Java concurrent programming principle and practice three: Multi-threading and multi-process connection and the problem of resource wasting caused by context switch

computer system. Parallel processing can work on different aspects of the same program at the same time. The main purpose of parallel processing is to save time to solve large and complex problems. Concurrent processing (concurrency processing): Refers to a time period in which several programs are running to completion, and these programs are running on the same processor (CPU), but only one program at any point on the processing machine (CPU) runsThe key to concurrency is that you have the ab

Shell Programming Basics Break, Continue practice

First, the grammarBreak: Used to jump out of a loop. Break N can jump out of a multilayer loopBreakBreak NContinue: Used to skip loops. Continue N can skip multi-layer loopsContinueContinue NIi. details and differences Break forVar1inch 1 2 3 Do forVar2inch 0 5 Do if["$var 1"-eq"2"-A"$var 2"-eq"0"]; Then Break2 Else Echo "$var 1 $var 2" fi Done Done[Email protected]:~$./test. SH 1 0 1 5 Continue forVar1inch 1 2 3 Do forVar2inch 0 5 Do if["$var 1"-eq"2"-A"$var 2"-

"C + + programming principles and Practice" reading notes (iv)

operator:First, the destructor of the vector is activated; The constructor activates the destructors for these elements (if they have destructors), and then releases the memory used by those elements.Then, release the memory used by the vector.Type blending: untyped pointers and pointer type conversionsWe are very close to the hardware level when using pointers to free-space allocation arrays. Basically, we map the operation of pointers (initialization, assignment, * and []) directly to machine

Socket Programming Practice (4)--Multi-process concurrent server

on = 1; if (setsockopt (Listenfd,sol_socket,so_reuseaddr, on,sizeof (on)) = =-1) err_exit ("setsockopt SO_REUSEADDR error "); struct sockaddr_in addr; addr.sin_family = af_inet; Addr.sin_port = htons (8001); ADDR.SIN_ADDR.S_ADDR = htonl (Inaddr_any); if (Bind (LISTENFD, (const struct sockaddr *) addr, sizeof (addr)) = =-1) err_exit ("Bind error"); if (Listen (LISTENFD, somaxconn) = =-1) err_exit ("Listen error"); struct sockaddr_in clientaddr; socklen_t Addrlen = size

C + + Programming practice Guidance 1.15 Find the palindrome number rewrite requirements to achieve

Rewrite requirement 1: Implemented with single-linked list#include #includeusing namespacestd;structlinknode{intdata; Linknode*next;};classpalindrome{intLow,up; inta[ -]; intcount; Public: Palindrome (intT1,intT2); intIspalin (intx); Linknode*Ispalinandstore (); voidOutputresults (linknode*Head);}; Palindrome::P alindrome (intT1,intT2) {Count=0; Low=T1; up=T2;} Linknode*Palindrome::ispalinandstore () {Linknode* head=NewLinknode; Head->next=NULL; Linknode* p=Head; for(inti=low;i) {

Total Pages: 15 1 .... 11 12 13 14 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.