c++语言二维数组例题,c++语言基础--数组.ppt

c++语言基础--数组.ppt

第五章 数组 例5.16 对给定的10个国家名,按其字母的顺序输出。 【参考程序1】   #include   #include   #include   using namespace std;   int main()   { char t[21],cname[11][21];    for (int i=1; i<=10; ++i) gets(cname[i]); //gets为专门读字符串的函数, 读取一行字符串    for (int i=1; i<=9; ++i)    { int k=i;    for (int j=i+1; j<=10; ++j)    if (strcmp(cname[k],cname[j])>0) k=j;    strcpy(t,cname[i]);    strcpy(cname[i],cname[k]);    strcpy(cname[k],t);    }    for (int i=1; i<=10; ++i) cout<   #include   #include   using namespace std;   string cname[10];   int main(){ for (int i=0;i!=10;++i) getline(cin,cname[i]); sort(cname,cname+10);//利用C++库函数排序 for (int i=0;i!=10;++i) cout< #include #include #include using namespace std; string word,str; int main(){ int first=0,ans=0; cin>>word; word=" "+word+" "; for (string::size_type i=0;i!=word.size();++i)//string::size_type为无符类型 word[i]=toupper(word[i]); getline(cin,str); //当我们读完word后,还有换行符 getline(cin,str); str=" "+str+" "; for (string::size_type i=0;i!=str.size();++i) str[i]=toupper(str[i]); for (string::size_type i=str.find(word);i

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值