ECNU 1073 几位数?
链接
https://acm.ecnu.edu.cn/problem/1073
题目
单点时限: 2.0 sec
内存限制: 256 MB
旺财视力越来越差了,刚好这几天数学作业总是要对很长很长的数字进行加减,每次旺财看到这么长的数字总想先数数它是几位数。
可他数着数着眼就花了,不得不重新从个位数起,现在想请你写程序帮他解决这个问题。
输入格式
每行输入一个非负整数,这个非负整数不会超过 1024 位。
行数不会超过 100 行。
输出格式
每行只输出一个正整数,为对应的非负整数的位数。
样例
input
1
100123
12345678901234567890
output
1
6
20
思路
都不用数的,直接计算字符串长度就行了,当做字符串输入即可。
代码
public static void fun() {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.next();
System.out.println(str.length());
}
}