LSNUOJ 1102

1102: 统计字符
时间限制: 1 Sec 内存限制: 128 MB
提交: 166 解决: 114
[提交] [状态] [讨论版] [命题人:外部导入]
题目描述

统计一个字符串中字母、数字、空格和其它字符的个数。

输入

一行字符串

输出

字符串中字母、数字、空格和其它字符的个数,每个数字后面都用空格分开。

样例输入
!@#$%^QWERT 1234567

样例输出
5 7 4 6

来源/分类

import java.util.Scanner;

public class OJ1102 {

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		String string=new String();
		string=scanner.nextLine();
		int a=0,b=0,c=0,d=0;
		for(int i=0;i<string.length();i++)
		{
				if((string.charAt(i)>='a'&&string.charAt(i)<='z'))
					a++;
				else
				{
					if(string.charAt(i)>='A'&&string.charAt(i)<='Z')
						a++;
					else 
					{
						if(string.charAt(i)>='0'&&string.charAt(i)<='9')
							b++;
						else
						{
							if(string.charAt(i)==' ')
								c++;
							else 
								d++;
						}
					}
				}
		}
//		System.out.println(string);
		System.out.printf(a+" "+b+" "+c+" "+d+"\n");
	}

}

posted @   付玬熙  阅读(52)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
主题色彩