qq_45735316 2020-04-19 13:03 采纳率: 94.1%
浏览 528
已采纳

为什么不能转换?这报错是什么意思?

图片说明

#include <iostream>
#include <string.h>
#include <algorithm>
#define N 100
using namespace std;
int *culculate(string *str)
{
    int n=strlen(str);
    int a[26];
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++)
    {
        if(str[i]>='a'&&str[i]<='z'&&str[i]>='A'&&str[i]<='Z')
        {
            if(isupper(str[i]))
            {
                str[i]=tolower(str[i]);
            }
            a[(int)(str[i]-'a')]++; 
        }
        return a;
    }
}
int main()
{
    string str;
    cin>>str;
    int a[26]={0};
    a=culculate(str);
    int s=0;
    int max=a[0];
    for(int i=0;i<26;i++)
    {
        if(max<a[i])
        {
            max=a[i];
        }
        s+=a[i];
    }
    cout<<"字母个数为"<<s<<endl; 
    cout<<"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"<<endl;
    cout<<"---------------------------------------------------"<<endl; 
    for(int i=0;i<max;i++)
    {
        for(int j=0;j<26;j++)
        {

            if(a[j])
            {
               cout<<"*"<<" ";
               a[j]--;
            }
        }
        cout<<endl;
    }

}
  • 写回答

2条回答 默认 最新

  • weixin_42232897 2020-04-19 23:50
    关注

    #include
    #include //改
    #include
    #define N 100
    using namespace std;
    int culculate(string *str)
    {
    int n=str->length();//改 int n=strlen(str);
    //int a[26];
    static int b[26];//改 C++不支持在函数外返回局部变量的地址,除非定义局部变量为 static 变量。
    memset(b,0,sizeof(b));
    for(int i=0;i {
    if((*str)[i]>='a' && (*str)[i]<='z' && (*str)[i]>='A' && (*str)[i]<='Z')//改(*str)[i]
    {
    if(isupper((*str)[i]))
    {
    (*str)[i]=tolower((*str)[i]);
    }
    b[(int)((*str)[i]-'a')]++;
    }
    return b;
    }
    return b;//增加一个 你自己再看看
    }
    int main()
    {
    string str;
    cin>>str;
    //int a[26]={0};
    /
    一个指向整数的指针 */
    int *a;
    //a=culculate(str);//改
    a=culculate(&str);//改
    int s=0;
    int max=a[0];
    for(int i=0;i<26;i++)
    {
    if(max<a[i])
    {
    max=a[i];
    }
    s+=a[i];
    }
    cout<<"字母个数为"<<s<<endl;
    cout<<"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"<<endl;
    cout<<"---------------------------------------------------"<<endl;
    for(int k=0;k<max;k++)//i重复 改成k
    {
    for(int j=0;j<26;j++)
    {

            if(a[j])
            {
               cout<<"*"<<" ";
               a[j]--;
            }
        }
        cout<<endl;
    }
    return 0;
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 9月25日

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)