第2个回答 2009-05-11
第一题
#include<iostream>
#include<cstdlib>
#include<string>
#include<ctype.h>
using namespace std;
int main()
{
cout<<"输入字符串(长度不超过80):"<<endl;
char* ch=new char[80];
string str;
cin.getline(ch,80);
str=ch;
cout<<"原始字符串:"<<endl;
cout<<str<<endl;
for(int i=0;i<str.length();i++)
{ if(!isalpha(str[i]))
{
str.erase(i,1);
i--;
}
else if(islower(str[i]))
str[i]-=32;
}
cout<<"修改后的字符串:"<<endl;
cout<<str<<endl;
int word[26]={0};
for(int j=0;j<str.length();j++)
{
for(int k=65;k<90;k++)
if(str[j]==k)
{
word[k-65]++;
break;
}
}
for(int m=0;m<26;m++)
cout<<(char)(m+65)<<":"<<word[m]<<endl;
delete [] ch;
system("PAUSE");
return 0;
}
第二题
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int num,subnum;
cout<<"输入长整数:"<<endl;
cin>>num;
char ch[20];
sprintf(ch,"%d",num);
string str=ch;
cout<<"str:"<<str<<endl;
for(int i=str.length()-3;i>=0;i-=3)
str.insert(i,1,',');
cout<<str;
system("PAUSE");
return 0;
}
第3个回答 2009-05-11
都用字符数组做的 看这意思是要考察字符数组了 没有太复杂的头文件和函数
#include<iostream>
using namespace std;
int main()
{
char c[81];
cin>>c;
int length=strlen(c),
i=0,
count[26];
while(i<length)
{
if((c[i]<'a'||c[i]>'z')&&(c[i]<'A'||c[i]>'Z'))
{
for(int j=i;j<length;j++)
c[j]=c[j+1];
length--;
}
else i++;
}
for(i=0;i<26;i++)
count[i]=0;
for(i=0;i<length;i++)
{
if(c[i]>='a'&&c[i]<='z')
c[i]-=32;
count[int(c[i]-'A')]++;
}
cout<<c<<endl;
for(i=0;i<26;i++)
{
if((i+1)%8==0)
cout<<endl;
cout<<char('A'+i)<<':'<<count[i]<<' ';
}
cout<<endl;
return 0;
}
/////////////////////////////////////////////
#include<iostream>
using namespace std;
int main()
{
char a[80];
cin>>a;
int length=strlen(a),
i,n;
n=length%3;
for(i=0;i<n;i++)
cout<<a[i];
for(i=0;i<length-n;i++)
{
if(n==0)
{
if(i>2&&i%3==0) cout<<',';
}
else if(i%3==0) cout<<',';
cout<<a[i+n];
}
cout<<endl;
return 0;
}
第4个回答 2009-05-11
第一题:
#include <iostream.h>
#include <string.h>
void main()
{
char line[81];
int times[26] = {0};
int i, j, l;
char ch;
l = strlen(line);
cin.getline(line, 81);
for (i = 0; line[i]; ++i)
{
if ((line[i] >= 'a') && (line[i] <= 'z'))
line[i] -= 32;
if (!(line[i] >= 'A' && line[i] <= 'Z'))
{
--l;
for (j = i; j < l - 1 ; ++j)
line[j] = line[j + 1];
--i;
continue;
}
++times[line[i]-'A'];
}
line[l] = '\0';
cout << line << endl;
for (i = 0; i < 26; ++i)
{
if (times[i] != 0)
{
ch = 'A' + i;
cout << ch << " : " << times[i] << endl;;
}
}
}
第二题:
#include <iostream.h>
void main()
{
long num;
int rem[10] = {0};
int i, j;
i = 0;
cin >> num;
if (num == 0)
{
cout << 0 << endl;
return;
}
while (num)
{
rem[i++] = num % 1000;
num /= 1000;
}
for (j = i - 1; j >= 0; --j)
{
if ( i == 1)
{
cout << rem[0];
break;
}
if (j == i - 1)
cout << rem[j] << ',';
else
{
if (rem[j] < 10)
cout << "00" << rem[j];
else if (rem[j] < 100)
cout << '0' << rem[j];
else
cout << rem[j];
if (j != 0)
cout << ',';
}
}
cout << endl;
}
第5个回答 2009-05-11
我QQ:245495273,有问题问我吧。你的程序我马上准备去写。