华为校招 解析报文,找出字符段的输出

来源:互联网 发布:linux 服务器重启 编辑:程序博客网 时间:2024/06/06 14:26
输入的是:char str[]="name=justin,age=18,gender=male,job=sew";输出 是:[[name,justin],[age,18],[gender,male],[job,sew]]
</pre><pre code_snippet_id="1837821" snippet_file_name="blog_20160818_1_9037031" name="code" class="cpp"><pre name="code" class="cpp">#include<iostream>using namespace std;int main(){//char str[]="name=justin,age=18,gender=male,job=sew";char str[100];cin>>str;char s[100];char *p,*q;p=str;q=s;*q='[';q++;while(*p!=NULL){if(*p!=','&&*p!='='){*q++=*p;}else if(*p=='='){*q++=',';}else if(*p=','){*q++=']';*q++=',';*q++='[';}p++;}*q++=']';*q='\0';cout<<"["<<s <<"]"<<endl;}


                                             
0 0