| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 575 人关注过本帖
标题:多谢
只看楼主 加入收藏
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:8 
多谢
#include <iostream>
 using namespace std;
 int main()
 {
     char str[100];
     int i=0,a=0,b=0,c=0,d=0;
     cout<<"input a string:  ";
     cin>>str;
     while(str[i]!='\0')
       {
         if(str[i]==' ')
         a++;
         else if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
         b++;
         else if(str[i]>='0'&&str[i]<='9')
         c++;
         else
         d++;
         i++;
     }
     cout<<"the number of space is"<<a<<endl;
     cout<<"the number of letter is"<<b<<endl;
     cout<<"the number of figure is"<<c<<endl;
     cout<<"the number of else character"<<d<<endl;
     return 0;
}

[ 本帖最后由 wjffirework 于 2015-3-15 14:35 编辑 ]
搜索更多相关主题的帖子: include number 
2015-03-14 19:48
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
收藏
得分:0 
我要是改为for循环就可以while就不输出结果
2015-03-14 19:51
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:5 
i没有初始化

一片落叶掉进了回忆的流年。
2015-03-14 20:44
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
收藏
得分:0 
回复 3楼 诸葛欧阳
试过了,给i赋值还是不输出结果
2015-03-14 22:21
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
收藏
得分:0 
回复 3楼 诸葛欧阳
刚开始就有试过但是一直好像不跳出那个循环
2015-03-14 22:26
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:99
专家分:181
注 册:2014-9-9
收藏
得分:5 
你这一题只能验证你输入的第一个数和后面的空格,不知你是不是这样的意思,虽然有点笨。
#include <iostream>
using namespace std;
int main()
{
     char str[100];
     int i,a=0,b=0,c=0,d=0;
     cout<<"input a string:  ";
     cin>>str;
     for(i=0;i<100;i++)
     {
         if(str[i]==' ')
         a++;
         else if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
         b++;
         else if(str[i]>='0'&&str[i]<='9')
         c++;
         else
         d++;
         cout<<"input a string:  ";
         cin>>str;
         i++;
     }
     cout<<"the number of space is"<<a<<endl;
     cout<<"the number of letter is"<<b<<endl;
     cout<<"the number of figure is"<<c<<endl;
     cout<<"the number of else character"<<d<<endl;
  system("pause");
  return 0;
}

今朝醉
2015-03-14 22:33
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:0 
程序代码:
#include <iostream>
using namespace std;
int main()
{
     char str[30];
     int i=0,a=0,b=0,c=0,d=0;
     cout<<"input a string:  ";
     cin>>str;
     while(str[i]!='\0')//不要分号
     {
         if(str[i]==' ')
         a++;
         else if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
         b++;
         else if(str[i]>='0'&&str[i]<='9')
         c++;
         else
         d++;
         i++;
     }
     cout<<"the number of space is"<<a<<endl;
     cout<<"the number of letter is"<<b<<endl;
     cout<<"the number of figure is"<<c<<endl;
     cout<<"the number of else character"<<d<<endl;
     return 0;
}

一片落叶掉进了回忆的流年。
2015-03-14 22:34
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
收藏
得分:0 
回复 6楼 zcdjt
我那个的意思是输入一串字符,统计其中数字,空格,字母和其他字符的个数输出,我刚开始改为for循环可以,但用while就不输出结果
2015-03-15 09:28
wjffirework
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-3-12
收藏
得分:0 
回复 7楼 诸葛欧阳
多谢

[ 本帖最后由 wjffirework 于 2015-3-15 10:11 编辑 ]
2015-03-15 09:31
快速回复:多谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016562 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved