游客 Signup | Login
中文 | En

1192 - C语言7.16

通过次数

0

提交次数

0

Time Limit : 1 秒 Memory Limit : 32 MB

给出一篇文章,共有3行文字,每行有最多80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。

Input

共有3行,表示输入的文章。

Output

在一行中输出文章中的英文大写字母、小写字母、数字、空格以及其他字符的个数,用空格隔开。

请注意行尾输出换行。

Examples

Input Format

I am a program.
This is the second line!
And this is the last line........

Output Format

3 47 0 12 10

Solution C

#include <stdio.h>
int main() {
        char p[3][81];
        int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0;
        for (i = 0;i < 3;i++) {
                gets(p[i]);
        }
        for (i = 0;i < 3;i++) {
                for (j = 0;p[i][j] != '\0';j++) {
                        if ('A' <= p[i][j] && p[i][j] <= 'Z')
                                upper++;
                        else if ('a' <= p[i][j] && p[i][j] <= 'z')
                                lower++;
                        else if ('0' <= p[i][j] && p[i][j] <= '9')
                                digit++;
                        else if (p[i][j] == ' ')
                                space++;
                        else
                                other++;
                }
        }
        printf("%d %d %d %d %d\n", upper, lower, digit, space, other);
        return 0;
}

Solution C++

#include <stdio.h>
int main() {
	char p[3][81];
	int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0;
	for (i = 0;i < 3;i++) {
		gets(p[i]);
	}
	for (i = 0;i < 3;i++) {
		for (j = 0;p[i][j] != '\0';j++) {
			if ('A' <= p[i][j] && p[i][j] <= 'Z')
				upper++;
			else if ('a' <= p[i][j] && p[i][j] <= 'z')
				lower++;
			else if ('0' <= p[i][j] && p[i][j] <= '9')
				digit++;
			else if (p[i][j] == ' ')
				space++;
			else
				other++;
		}
	}
	printf("%d %d %d %d %d\n", upper, lower, digit, space, other);
	return 0;
}

Solution Java



import java.util.Scanner;

public class Main {
   private static Scanner s = new Scanner(System.in) ;
   
   public static void main(String[] args) {
	  String str = "" ;
	  for (int i = 0; i < 3; i++) {
		 String str1 = s.nextLine() ;
		 str+=str1 ;
	  }
	  char c[] = str.toCharArray() ;
	  
	  int a = 0 ;
	  int b = 0 ;
	  int d = 0;
	  int e = 0;
	  int f = 0 ;
	  
	  for (int i = 0; i < c.length; i++) {
		 if(c[i]<='Z'&&c[i]>='A'){
			 a++ ;
		 }else if(c[i]<='z'&&c[i]>='a'){
			 b++ ;
		 }else if(c[i]<='9'&&c[i]>='0'){
			 d++ ;
		 }else if(c[i]==' '){
			 e++ ;
		 }else f++ ;
		 
	  }
	  
	  System.out.println(a+" "+b+" "+d+" "+e+" "+f);
   }
}