浙大1303 手机靓号

手机靓号
Time Limit:1000MS  Memory Limit:32768K


Description:
小风凉刚买了手机,去营业厅开户,营业员让其挑选自己喜欢的号码,但那么多的号码着实让他眼花,他对号码的要求是在号码中6和8的个数要超过5个,并且没有数字4,于是就由我给他编了一个程序。

Input:
输入不多于50组的数(手机号码),每个数以13或15开头,长为11位。
Output:
输出数中,含有6和8不少于5个,并且没有4的数,并统计号码的个数。
Sample Input:
13656689866
13805880343
15967126781
13808866888
Sample Output:
13656689866
13808866888
2

解答:

#include <iostream>
#include <string>//用string,可以很简单地检测出输入的一串字符的结尾
using namespace std;
bool f(string &str)
{
  int c=0,len=str.size();  //不包括最后的结束符
  for(int i=0;i<len;i++)//不要写成i<=len,因为作为数组下标它是从0到len-1的
  {
   if(str[i]=='8' || str[i]=='6') c++;
   if(str[i]=='4') return false;
       
  }
   if(c>=5) return true;
   else
   return false;   
}
int main()
{string str;
bool flag;
int t=0;;
while(cin>>str) //接收到回车就可以判断出是输入完成了
{
  flag=f(str);//要给参数
  if(flag)
  {
  cout<<str<<endl;
  t++;    
  }
          
}
 cout<<t<<endl;   //要按ctrl+z才能看到输出,
 //在vc6.0下需要按两次,这是vc6.0的一点bug
  system("pause");
   return 0;
}

posted on 2010-03-21 18:00  蓝牙  阅读(316)  评论(0编辑  收藏  举报