统计 水NOJ 1599

来源:互联网 发布:javascript 控制台输出 编辑:程序博客网 时间:2024/05/18 22:44


统计

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 449            测试通过 : 135 

题目描述

编程统计一段文字中的英文字母和数字的数目。

输入

输入一段文字,其中字符数不超过106

输出

在一行中依次输出英文字母、数字的数目,两种之间以一个空格分隔

样例输入

    while (n!=1)
    {
        sum=sum+n;
        if (n % 2 == 1)
            n = n*3 +1;
        else n = n/2;
        count++;
    }
    printf(?%.3lf\n", sum/count);
    return 0;

样例输出

52 8

提示

 


实现代码:

#include<iostream>#include<stdlib.h>#include<stdio.h>#include<string.h>#include<math.h>using namespace std;int n=0,m=0;const int N=1000000+10;char a[N];int main(){    char c;  //  freopen("data.in","r",stdin);    while((c=getchar())!=EOF)      {        if(c>='0'&&c<='9')        {            ++m;        }        if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))        {            ++n;        }    }    printf("%d %d\n",n,m);}
0 0
原创粉丝点击