1057 数零壹
输入格式
输入在一行中给出长度不超过 10的5次方 、以回车结束的字符串。
输出格式
在一行中先后输出 0 的个数和 1 的个数,其间以空格分隔。注意:若字符串中不存在字母,则视为 N 不存在,也就没有 0 和 1。
输入样例
PAT (Basic)
输出样例
3 4
代码示例
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
int main() {
char s[100001];
gets(s);
int c = 0;
for(int i=0; s[i]!='\0'; i++) {
if(s[i]>='a'&&s[i]<='z') {
c+=s[i]-'0'-48;
} else if(s[i]>='A'&&s[i]<='Z') {
c+=s[i]-'0'-16;
}
}
int a[1000]= {0};
int b[3]= {0};
int i = 0;
while(c!=0) {
a[i++] = c%2;
b[c%2]++;
c/=2;
}
printf("%d %d",b[0],b[1]);
return 0;
}