SHARE
TWEET

Untitled

a guest May 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. char c,d;
  5. int valid_sequence_counter = 0; // how many sequences
  6. int num_of_valid_chars = 0; // how many chars inside these sequences
  7. int invalid_sequence_counter = 0; //how many chars are not in valid sequence
  8. int sequence_size = 0;
  9. int lastDigit = 0;
  10. int badFlag = 0;
  11.  
  12. int main() {
  13.     while ((c = getchar()) != '@') {
  14.        
  15.         if (c >= '1' && c <= '9' ) {
  16.             if (sequence_size != lastDigit || badFlag) {
  17.                 invalid_sequence_counter += sequence_size;
  18.                 sequence_size = 0;
  19.             }
  20.             else if(lastDigit>0) {
  21.                 valid_sequence_counter++;
  22.                 num_of_valid_chars += sequence_size;
  23.             }
  24.             lastDigit = c - '0';
  25.             sequence_size = 0;
  26.             badFlag = 0;
  27.            
  28.         }
  29.         else if(lastDigit>0 && !badFlag) {
  30.             sequence_size++;
  31.             if (sequence_size != 1 ) {
  32.                 if (d + 1 != c) {
  33.                     badFlag = 1;
  34.                 }
  35.             }
  36.             d = c;
  37.         }
  38.         else {
  39.             sequence_size++;
  40.         }          
  41.     }
  42.     if (sequence_size != lastDigit ||badFlag) {
  43.         invalid_sequence_counter += sequence_size;
  44.     }
  45.     else {
  46.         valid_sequence_counter ++;
  47.         num_of_valid_chars += sequence_size;
  48.     }
  49.     printf("sequences: %d \n valid char count: %d \n invalid char count: %d \n", valid_sequence_counter, num_of_valid_chars, invalid_sequence_counter);
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top