c++ 帮忙啊 ! 今晚天上要交的!谢谢啊

1.从键盘上输入一个字符串,假定长度不超过80个字符,试去除其中的非英文字母(字符串的长度缩短),并将其中的小写英文字母全部转化为大写,最后输出该字符串并分别统计输出每一种英文字母的个数。
2.将用户输入的一个正整数n(长整型)输出成“千分位”形式,即从个位数起,每三位之间加一个逗号,例如:将7654321输出成7,654,321。

哈,你运气真好,有些人问这种题目十几天都不一定有人理他;我刚好第一题编不来,有贵人助你,人品爆发了你……
2.
#include<iostream.h>
#include<malloc.h>
char *separate(int);
char *exchange(int);
void main()
{
int num;
char *p;
cout<<"输入一个整数:";
cin>>num;
p=separate(num);
cout<<"输出结果:"<<p<<endl;
}
char *separate(int num)
{
char *p1, *p2=exchange(num),*p3,*pt;
int count=1;
p1=p2;
while (*p2++!='\0');
p3=p2-1; //p3指向字符串的结束标志'\0'
p2=p2-2; //p2指向字符串最后一个有效字符
while (p2>p1) //从后向前操作
{
if (count==3) //计数3个字符
{
pt=p3++;
while (pt>=p2)
*(pt+1)=*pt--;
*p2=','; //插入一个逗号
count=0;
}
count++;
p2--;
}
return p1;
}
char *exchange(int num) //将整数num转换成对应的数字字符串
{
char *p,*p1,*p2,temp;
p=p1=p2=(char *)malloc(20*sizeof(char));
while (num!=0)
{
*(p2++)=num%10+'0';
num/=10;
}
*(p2--)='\0';
while (p2>p1)
{
temp=*p2;
*p2--=*p1;
*p1++=temp;
}
return p;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-05-11
你选择放弃吧
第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,有问题问我吧。你的程序我马上准备去写。
相似回答
大家正在搜