
字符串
Howe Tan浪漫的季节
编程是一种艺术,在艺术的殿堂里我乐此不彼。
展开
-
找出01字符串中0和1连续出现的最大次数
#include<iostream>using namespace std;void calculate(char *src,int *max0,int *max1){ int temp0=0,temp1=0; while(*src) { if(*src=='0') { (*max0)++; if(*(++src)=='1') { if(...原创 2019-06-29 16:12:22 · 845 阅读 · 0 评论 -
编程实现库函数strcat
#include<iostream>using namespace std;char *mystrcat(char *dest,char *src){ char *temp=dest;//保存首地址便于返回 while(*dest++); dest--;//把指针指向指向字符串结束符 while(*dest++=*src++); return temp;}int ...原创 2019-06-29 16:17:04 · 272 阅读 · 0 评论 -
给定一列非负整数,求这些数连接起来能组成的最大的数。
#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;bool compare(string &a, string &b) { return (a + b) > (b + a);}...原创 2019-07-14 21:49:43 · 293 阅读 · 0 评论 -
C++实现字符串中查找子串,也即实现strstr函数
#include<iostream>using namespace std;int main(){ char *strstr(char *src,char *sub); char p[256]; char q[256]; cout<<"input the src:"<<endl; cin>>p; cout<<"inp...原创 2019-06-30 16:46:17 · 4553 阅读 · 0 评论 -
C++实现统计字符串中,单词的总个数,不同单词的个数以及不同单词出现的频率
1;首先使用getline()输入一行字符串;2:以空格为分隔符,将字符串进行分割并存放在vector中;3:建立一个map(string,int),将vector中元素放入map中,以string作为键,每次出现一个就加一,则与键对应的值就是单词出现的频率;4:输出,每个单词及其出现的次数;// 统计单词出现的频率.cpp : 定义控制台应用程序的入口点。//#inclu...原创 2019-08-23 16:19:19 · 8033 阅读 · 5 评论