fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(){
  7. int n;
  8. cin >> n;
  9. int m;
  10. cin >> m;
  11. string s = to_string(m);
  12. int arr[n];
  13. cout << "Before: ";
  14. for(int i = 0; i < n; ++i)
  15. cout << arr[i] << ' ';
  16. cout << endl;
  17. int j = 0;
  18. for(auto d : s){
  19. arr[j] = d-'0';
  20. j += 1;
  21. }
  22. cout << "After: ";
  23. for(int i = 0; i < n; ++i)
  24. cout << arr[i] << ' ';
  25. cout << endl;
  26. }
Success #stdin #stdout 0s 5536KB
stdin
4 0135
stdout
Before: 192148128 32767 -496238205 21846 
After: 1 3 5 21846