鱼C论坛

 找回密码
 立即注册
查看: 3421|回复: 4

C++问题 大神求助

[复制链接]
发表于 2013-10-16 15:18:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 zoe琦 于 2013-10-16 15:19 编辑

这是我写的程序  但是我在子函数那一部分没有头绪要怎么写  求大神指教
#include <iostream>

using namespace std;

void count(const char si[],int counts[])
{
    for(i=0;i<si.size();i++)
    {
        if(si[i][i]>='A'&&si[i][i]<='Z')
                s[i]=+32;
  for(k=0;k<counts.size;k++)
  {
      if(counts[k]==si)
      {


      }
      }
  }
  }


int main()
{
    string si;
    int counts[26]={'a','b','c','d','e','f','g','h','y','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
    cout << "Enter a string :" ;
    getline(cin,si);

    count(const char si[],int counts[])
    return 0;
}


这是预期结果:

预期结果

预期结果

[/i][/i][/i]
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-10-16 15:20:52 | 显示全部楼层
自己顶下:lol:
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-10-16 15:43:13 | 显示全部楼层
本帖最后由 苹果沃珂 于 2013-10-16 16:03 编辑
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. void count( char* si,int counts[26])
  5. {
  6.         int i;
  7.         for(i=0;i<strlen( si);i++)
  8.         {
  9.                 if(si[i]>='A'&&si[i]<='Z')
  10.                         si[i] += 32;
  11.                 if (si[i]>='a'&&si[i]<='z')
  12.                 {
  13.                         counts[si[i]-97]++;  // 统计26个字母的个数
  14.                 }
  15.         }
  16.         for( i=0; i<26; i++)
  17.         {
  18.                 if ( counts[i] > 0 )
  19.                 {
  20.                         printf( "%c: %d\n", i+97, counts[i] );  // 打印有计数的字母
  21.                 }
  22.         }
  23. }


  24. int main()
  25. {
  26.         string si;
  27.         cout << "Enter a string :" ;
  28.         getline(cin, si);
  29.         int counts[26] = { 0 };
  30.         count( (char*)si.c_str(),counts );
  31.         return 0;
  32. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-10-16 16:03:43 | 显示全部楼层
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. void count( char* si,int counts[26])
  5. {
  6.         int i;
  7.         for(i=0;i<strlen( si);i++)
  8.         {
  9.                 if(si[i]>='A'&&si[i]<='Z')
  10.                         si[i] += 32;
  11.                 if (si[i]>='a'&&si[i]<='z')
  12.                 {
  13.                         counts[si[i]-97]++;  // 统计26个字母的个数
  14.                 }
  15.         }
  16.         for( i=0; i<26; i++)
  17.         {
  18.                 if ( counts[i] > 0 )
  19.                 {
  20.                         printf( "%c: %d\n", i+97, counts[i] );  // 打印有计数的字母
  21.                 }
  22.         }
  23. }


  24. int main()
  25. {
  26.         string si;
  27.         cout << "Enter a string :" ;
  28.         getline(cin, si);
  29.         int counts[26] = { 0 };
  30.         count( (char*)si.c_str(),counts );
  31.         return 0;
  32. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-20 21:41:12 | 显示全部楼层
:mad::mad::mad::mad:哎,快来大神
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-10 20:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表