#include <iostream>#include <malloc.h>#include <string.h>using namespace STD;//The spaces in the string are replaced with%20. voidGrial (Char*STR) {if(Str==null)return;Char*p = str;Char*q = NULL;Charbuf[strlen(str) +1];intCount =0;//Count the number of spaces. while(*p!=' + ') {if(*p=="') Count + +; p++; }strcpy(BUF,STR);intn =strlen(str) +2*count+1; str = (Char*)malloc(n);memset(STR,' + ',sizeof(str));strcpy(STR,BUF); p = str+n-1;//n is the length of the string including ' s ', I want p to point to the next ' I ' position, and I let str+n point to the position behind ' /', //So p=str+n-1 is pointing to the next position ' ", why do I have to write this, I tangled for half a day how dislocation, Grandma's, //30 minutes without, after long memory. Q = p-count*2; while(1) {if(*q = ="') {*p=' 0 '; p--; *p=' 2 '; p--; *p='% '; }Else{*p = *q; }if(P==Q) Break; q--; p--; }cout<<str<<endl;}intMain () {Chara[]="You were a good boy!!!"; Grial (a);return 0;}/*---------------------------------------------------------------------------------------*/#include <iostream>//To increment a value in a two-dimensional array. //A classmate of mine met this question in a 2-face written examination. using namespace STD;intGrial (int(*a) [6],intXintYintVal) {inti = y1;intj =0; while(i!=0&& j!=x) {if(A[j][i]>val) {i--; }Else if(A[j][i]<val) {j + +; }Else{returnA[j][i]; } }return false; }intMain () {inta[][6]={1,3,4,6,7,9,2,4,5,7,9,Ten,4,5,7,8,Ten, -, };cout<<grial (A,3,6,3) <<endl;}
C + + uses%20 to replace spaces in strings (O (n) Time efficiency)