字符串数组
来源:互联网 发布:串口数据采集软件 编辑:程序博客网 时间:2024/05/29 02:24
//有3个国家名,找出按字母顺序排在最前面的国家字符串
代码如下:
#include <iostream>#include <string>using namespace std;int main(){ void smallest_string(char str[ ][30],int i);//函数声明 int i; char country_name[3][30];//定义二维字符数组,把一个二维字符数组看成3个一维字符数组,它们各有30个元素 for(i=0;i<3;i++) cin>>country_name[i]; smallest_string(country_name,3); //调用smallest_name函数,将字符数组名传递给形参 return 0;}void smallest_string(char str[ ][30],int n){ int i; char string[30]; strcpy(string,str[0]); //打擂台的算法 for(i=0;i<n;i++) if(strcmp(str[i],string)<0) strcpy(string,str[i]); cout<<endl<<"the smallest string is: "<<string<<endl; }
说明:只要更改此函数的部分参数,就能在任何情况下对字符进行比较。
0 0
- 字符串数组
- 数组、字符串
- 字符串数组
- 字符串数组
- 字符串数组
- 字符串数组
- 字符串数组
- 字符串数组
- 字符串数组
- 字符串数组
- 数组、字符串
- 数组,字符串
- 字符串数组
- 字符串,数组
- 字符串数组
- 字符串数组
- 数组,字符串
- 字符串 数组
- (四) Basic Build Customization(基本的构建定制 :签名,构建,混淆)
- 两段函数求值
- poj 2752 Seek the Name, Seek the Fame
- 浅析JVM
- 数据结构基础(24) --红黑树的设计与实现(下)
- 字符串数组
- 搭建SpringMVC开发环境
- 如何中断线程?
- 代码编写
- hdoj 1728 逃离迷宫 (BFS)
- Struts2如何查看工程下面所有action的URL
- hdoj 1686 Oulipo【kmp】
- JAVA代理机制中过的CGLIB代理自己关于的一点小小的理解
- HTML5绘制颜色渐变