PAT (Basic Level) Practise (中文) 1057. 数零壹(20)
来源:互联网 发布:淘宝嘻哈店铺 编辑:程序博客网 时间:2024/06/07 22:50
1057. 数零壹(20)
时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
给定一串长度不超过105的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串“PAT (Basic)”,其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个0、4个1。
输入格式:
输入在一行中给出长度不超过105、以回车结束的字符串。
输出格式:
在一行中先后输出0的个数和1的个数,其间以空格分隔。
输入样例:PAT (Basic)输出样例:
3 4
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); String str=input.nextLine(); str=str.toLowerCase(); //System.out.println(str); int sum=0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i)>='a'&&str.charAt(i)<='z') { sum+=(int)str.charAt(i)-96; } } String result=Integer.toBinaryString(sum)+""; //System.out.println(result); int count0=0; int count1=0; for (int i = 0; i < result.length(); i++) { if (result.charAt(i)=='0') { count0++; }else if (result.charAt(i)=='1') { count1++; } } System.out.println(count0+" "+count1); }}
阅读全文
0 0
- PAT (Basic Level) Practise (中文) 1057. 数零壹(20)
- PAT (Basic Level) Practise (中文)1057. 数零壹(20)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文)1027. 打印沙漏(20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)1027. 打印沙漏(20)
- Python 2 和 Python 3 之间的区别
- 集成算法-Xgboost
- swap分区
- Java 三大特性是:封装,继承,多态
- HDU6197 最长有序子序列 DP+二分查找
- PAT (Basic Level) Practise (中文) 1057. 数零壹(20)
- 学习Java小结-2
- 貌不惊人,但味道一定惊艳你
- BCD码和十进制的相互转换
- ForkJoin框架(一):ForkJoin框架概述
- HDU
- 将数据通过php语法存入到表里面
- 虚拟机入门二,虚拟机的三种网络模式
- 津津的储蓄计划