当前位置:网站首页>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
}
边栏推荐
- Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
- ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
- Jsonp function encapsulation
- Redis cache preheating & avalanche & breakdown & penetration
- Network security detection and prevention test questions (V)
- Case: count the most characters and times
- PostgreSQL change table owner
- Validation of TTF font by validator of laravel
- Tcp/ip test questions (III)
- Trend ea- fixed stop loss and profit per order
猜你喜欢

Arduino read temperature

Mail monitoring cloud script execution progress

Record Baidu search optimization thinking analysis

Vulnhub range - the planes:venus

Panda weekly -2022/02/18

Two types of attribute injection methods

What is an operator?

On Oracle full stack virtual machine -- graalvm

Apifox simple understanding -- the integrator of web side testing

Paddleocr learning (II) paddleocr detection model training
随机推荐
Electronic package to generate EXE file
Number of wechat applet custom input boxes
Record Baidu search optimization thinking analysis
PostgreSQL change table owner
Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
六、HikariConfig的配置解析
Miner's Diary: why should I go mining on April 5, 2021
Principles of MySQL clustered index and non clustered index
Genicam gentl standard ver1.5 (1)
五、HikariCP源码分析之初始化分析二
JS advanced
1、 Hikaricp source code analysis of connection acquisition process I
Idea common plug-ins
Uniapp waterfall flow, applet waterfall flow, very simple, suitable for the whole platform
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2
PAT B1056
Can the stock account opened through qiniu school be used? Is the fund safe?
Please do not call Page constructor in files
Paddleocr learning (II) paddleocr detection model training
Uncover ges super large scale graph computing engine hyg: Graph Segmentation