#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;
}
}
#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;
}
// Q1064361.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <stdlib.h>
#define N 100
using namespace std;
int *culculate(string *str)
{
int n=strlen(str->c_str());
int * a=new int[26];
memset((void *)a,0,sizeof(int)*26);
for(int i=0;i<n;i++)
{
if((str->c_str()[i]>='a'&&str->c_str()[i]<='z')||(str->c_str()[i]>='A'&&str->c_str()[i]<='Z'))
{
if(isupper(str->c_str()[i]))
{
a[(int)(str->c_str()[i]-'A')]++;
}
else
{
a[(int)(str->c_str()[i]-'a')]++;
}
}
}
return a;
}
int main()
{
string str;
cin>>str;
int *a;
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]--;
}
else
{
cout << " ";
}
}
cout<<endl;
}
}