import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.stream.IntStream;
import javax.print.attribute.standard.PrinterLocation;
import org.omg.CORBA.ORBPackage.InconsistentTypeCode;
public class Main
{
public Main()
{
// TODO Auto-generated constructor stub
}
public static void main(String[]args) throws FileNotFoundException
{
String string;
int count;
Scanner scanner = new Scanner( new File("C://Users//Administrator//Desktop//test.txt"));
while(scanner.hasNext())
{
string =scanner.next();
count = countAscii(string);
System.out.println(count);
}
}
private static int countAscii(String string)
{
char pos;
int num =0;
int[] ascii = new int[128];
// TODO Auto-generated method stub
for(int i =0;i<string.length();++i)
{
pos = string.charAt(i);
if(pos>=0&&pos<=127)
{
if(ascii[pos]==0)
{
ascii[pos] =1;
++num;
}
}
}
return num;
}
}
字符个数统计
参与人数:13时间限制:1秒空间限制:32768K
通过比例:73.68%
最佳记录:0 ms|8460K (来自 _DdEar)
算法知识视频讲解
题目描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127)。不在范围内的不作统计。
输入描述:
输入N个字符,字符在ACSII码范围内(0~127)。
输出描述:
输出字符的个数。
输入例子:
abc
输出例子:
3