SHARE
TWEET

Untitled

a guest Oct 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char s[100000];
  5.  
  6. long long int powerTwo(int power)
  7. {
  8.     long long int rslt = 1;
  9.     for (int i = 0; i < power; i++)
  10.         rslt = rslt * 2;
  11.     return rslt;
  12. }
  13.  
  14. int main()
  15. {
  16.     freopen("input.txt", "r", stdin);
  17.     freopen("output.txt", "w", stdout);
  18.  
  19.     int n;
  20.     int shift = 0;
  21.     int sum = 0;
  22.  
  23.     scanf("%d", &n);
  24.     scanf("%s", s);
  25.  
  26.     int rem = n % 8;
  27.    
  28.     for (int j = 0; j < n / 8; j++)
  29.     {
  30.         for (int i = 0; i < 8; i++)
  31.         {
  32.             sum += (int)(s[i + shift] - 48) * powerTwo(i);
  33.         }
  34.         printf("%d ", sum);
  35.         sum = 0;
  36.         shift += 8;
  37.     }
  38.     if (rem > 0)
  39.     {
  40.         for (int i = 0; i < rem; i++)
  41.         {
  42.             sum += (int)(s[i + shift] - 48) * powerTwo(i);
  43.         }
  44.         printf("%d", sum);
  45.         sum = 0;
  46.         shift += 8;
  47.     }
  48.  
  49.     return 0;
  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