数据结构与算法之 字符串
来源:互联网 发布:淘宝刷手小号 编辑:程序博客网 时间:2024/05/17 01:45
#include<iostream>using namespace std;int main(void){ char * p="abc"; char a[]="bdc"; cout<<strcmp(p,a)<<endl; return 0;}#include<stdio.h>#include<string.h>int main(void){ char a[64] ; char p[64] = "hello"; char * q = "world!"; char w[]="he llo world!"; char * ret =strcpy(a,p); char * ret1 =strcat(p,q); char * ret2 = strstr(p,q); char * buf = strtok(w," "); printf("%s\n%s\n%s\n%s\n",ret,ret1,ret2,buf); return 0;}//输入一行字符,统计其中有多少个单词,单词之间用空格分隔开。#include<iostream>#include <string>using namespace std;int main(void){ int i = 0,sum=1; /*string ch; getline(cin,ch);*/ char ch[64]; gets(ch) cout<<ch<<endl; while (1) { if(ch[i]==NULL) break; if (ch[i]==' ')//空格这一个字符要用单引号 { sum++; } i++; } cout<<"The number of words is:"<<sum<<endl; return 0;}//有3个字符串,要求找出其中的最大者#include<iostream>#include <string>using namespace std;int main(void){ /*string ch1,ch2,ch3,max; getline(cin,ch1); getline(cin,ch2); getline(cin,ch3); swap(max,ch1); if(ch1.compare(ch2)<0) swap(max,ch2); if(max.compare(ch3)<0) swap(max,ch3); cout<<"The maxium string is:"<<max<<endl;*/ char max[20]; char ch[3][20];//数组元素是[0][1][2] 没有[3] int i; for (i=0;i<=2;i++) { gets(ch[i]); } strcpy(max,ch[0]); if (strcmp(ch[0],ch[1])<0) strcpy(max,ch[1]); if(strcmp(max,ch[2])<0) strcpy(max,ch[2]); cout<<max<<endl; return 0;}
0 0
- 数据结构与算法之 字符串
- 数据结构与算法之KMP 字符串匹配
- 数据结构与算法--字符串
- 数据结构与算法:字符串
- 数据结构与算法:字符串
- 数据结构算法之字符串
- 【数据结构与算法】字符串匹配之BF&KMP算法
- 每日一帖:数据结构与算法之字符串旋转
- 每日一帖:数据结构与算法之字符串包含
- 每日一帖:数据结构与算法之字符串转整数
- 算法与数据结构八日谈之三——字符串
- 数据结构与算法系列---字符串
- 【数据结构与算法】字符串匹配KMP算法
- 【数据结构与算法】字符串匹配算法
- 《数据结构和算法》之字符串BF算法
- 数据结构与算法2:字符串与数组
- 数据结构与算法专题之串——字符串及KMP算法
- 数据结构与算法学习笔记之--数据结构
- 浅谈Java中的hashcode方法
- 乐观锁与悲观锁
- 生成多渠道apk文件
- 从零开始学习EasyDarwin(RTSP之TaskThread)
- easyui input 取值与赋值
- 数据结构与算法之 字符串
- 带环链表
- Java中的几种排序方法
- read/write函数
- XCODE 8 使用时遇到的bug及解决方案
- Apache Kafka 集群环境搭建
- 从零开始学习EasyDarwin之无锁队列
- phpexcel的使用
- SharePoint 2016 配置用户请求应用程序