Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int c, k;
- k = 0;
- int count = 0;
- int b = 0;
- int fourzeros = '0' * 1000000 + '0' * 10000 + '0' * 100 + '0';
- int ozzo = '1' * 1000000 + '0' * 10000 + '0' * 100 + '1';
- int f = -1; //определяет, BCD ли текущая четверка
- while ( ((c = getchar() ) != EOF) ) {
- if ((c != ' ') && (c != '\n')) {
- b = b * 100 + c;
- k++;
- }
- if (k == 4) {
- //printf("that is four = %d\n", b);
- if ((b >= fourzeros) && (b <= ozzo)) {
- // printf("she is BCD\n");
- f = 0;
- }
- else {
- f = 1; // f == 1 если текущая четверка не bcd
- }
- k = 0;
- b = 0;
- }
- if (c == ' ') {
- if (k != 0) {
- // printf("ne tetrada\n");
- k = 0;
- b = 0;
- f = -1;
- }
- else {
- if ((b == 0) && (f == 0)) {
- count++;
- // printf("OMG! BCD DETECTED!\n");
- }
- else {
- b = 0;
- f = -1;
- // printf("IT ISN'T BCD\n");
- }
- }
- }
- if (c == '\n') {
- if (k != 0) {
- // printf("ne tetrada\n");
- k = 0;
- b = 0;
- f = -1;
- }
- else {
- if ((b == 0) && (f == 0)) {
- count++;
- // printf("OMG! BCD DETECTED!\n");
- }
- else {
- b = 0;
- f = -1;
- // printf("IT ISN'T BCD\n");
- }
- }
- break;
- }
- }
- printf("number of BCD's is %d", count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement