当前位置:网站首页>PAT B1057
PAT B1057
2022-06-25 19:56:00 【Madness makes freedom】
1057 Count zero one (20 branch )
The length of a given string does not exceed 105 String , This question requires you to put the serial numbers of all English letters in it ( Letter a-z Corresponding serial number 1-26, Case insensitive ) Add up , Get the whole number N, And then analyze N How many in the binary representation of 0、 How many? 1. For example, given a string PAT (Basic), The sum of the letters and serial numbers is :16+1+20+2+1+19+9+3=71, and 71 The binary of is 1000111, That is to say 3 individual 0、4 individual 1.
Input format :
The input is given on a line, and the length is no more than 105、 String ending with carriage return .
Output format :
Output... Successively in one line 0 The number of and 1 The number of , Separated by spaces . Be careful : If there are no letters in the string , It is regarded as N non-existent , There is no 0 and 1.
sample input :
PAT (Basic)
sample output :
3 4#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
int main()
{
string str;
getline(cin,str);
int sum=0;
for(auto a : str)
{
int ch=0;
if(islower(a))
ch=a-'a'+1;
else if(isupper(a))
ch=a-'A'+1;
else
ch=0;
sum+=ch;
}
vector<int> ans;
if(sum==0)
{
cout << "0 0\n";
return 0;
}
while(sum!=0)
{
int x=sum%2;
sum/=2;
ans.push_back(x);
}
int count_0=0,count_1=0;
for(auto a : ans)
{
if(a==0)
++count_0;
else
++count_1;
}
// cout << count_0 << ends << count_1 << endl; //windows Yes ends Flush the buffer and output spaces ,
cout << count_0 << ' ' << count_1 << endl; //Linux Flush buffer only , Don't output spaces
return 0; // So use it with caution
}
边栏推荐
- Trend ea- fixed stop loss and profit per order
- 二、HikariCP获取连接流程源码分析二
- Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
- Record Baidu search optimization thinking analysis
- ActiveMQ--CVE-2016-3088
- Mysql database design suggestions
- Pdf file download (the download name is the same as the file name)
- mysql load data infile
- SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
- PostgreSQL change table owner
猜你喜欢

Uncover ges super large scale graph computing engine hyg: Graph Segmentation

PHP synchronizes website content to hundreds of websites to improve SEO ranking

Arduino read temperature

Laravel validation rule followed Role of auth:: id()

Verification code native JS canvas

Bloom filter

JS asynchronism (I. asynchronous concept, basic use of web worker)

Google cloud SSH enable root password login

Automatic fitting when the applet reaches the top

On Oracle full stack virtual machine -- graalvm
随机推荐
Applet Click to return to the top 2 methods
Principles of MySQL clustered index and non clustered index
What are Baidu collection skills? 2022 Baidu article collection skills
Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system
Trend ea- fixed stop loss and profit per order
Solidity date tool
Panda weekly -2022/02/18
MySQL prompt performance_ Schema missing table
From now on, I will blog my code
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
Pat b1054 average (20 points)
Mqtt+ardunio+esp8266 development (excluding mqtt server deployment)
rmi-registry-bind-deserialization
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2
Wechat applet connects to the server to display mqtt data information
Pdf file download (the download name is the same as the file name)
Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
一、HikariCP获取连接流程源码分析一
Appearance of object attributes
JS asynchronism (III. usage of generator and async/await)