思路:首先我们要把如果有英文字母的大写转换成小写来求出字符串的所代表数字,然后用除二取整法记录每一次0的个数和1的个数。
#include<cstdio>
#include<cstring>
#include<cctype>
int main(){
char c[
1000005];
gets(c);
int len=
strlen(c);
int N=
0;
for(
int i=
0;i<len;i++)
if(
tolower(c[i])>=
'a'&&
tolower(c[i])<=
'z')
N+=(
tolower(c[i])-
'a'+
1);
int count0=
0,count1=
0;
while(N){
if(N%
2) count1++;
else count0++;
N=N/
2;
}
printf(
"%d %d",count0,count1);
return 0;
}
题目链接:
https://www.patest.cn/contests/pat-b-practise/1057
转载请注明原文地址: https://ju.6miu.com/read-1132095.html