Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <bits/stdc++.h>
  5. #define zero '0'
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(){
  11. ifstream cin;
  12. ofstream cout;
  13. cin.open("input.txt");
  14. cout.open("output.txt");
  15. string st = "";
  16. vector <int> a;
  17. int pr = 0;
  18. int cn = 0;
  19. cin >> st;
  20. pr = st[0]-zero;
  21. cn++;
  22. //cout << st.length() << endl;
  23. for (int i=1; i<st.length(); i++){
  24. //cout << pr << endl;
  25. if (cn==pr+1){
  26. a.push_back(pr);
  27. //cout << st[i] << " ";
  28. pr = st[i]-zero;
  29. cn=0;
  30. }
  31. if (pr!=(st[i]-zero)){
  32. //cout << pr << endl;
  33. //cout << cn << endl;
  34. if (cn==pr+1){
  35. a.push_back(pr);
  36. //cout << st[i] << " ";
  37. pr = st[i]-zero;
  38. cn=0;
  39. }else{
  40. cout << -1;
  41. return 0;
  42. }
  43. }
  44. cn++;
  45. //cout << endl;
  46. }
  47.  
  48. if (cn==pr+1){
  49. a.push_back(pr);
  50. //cout << st[i] << " ";
  51. pr = st[st.size()-1]-zero;
  52. cn=0;
  53. }else{
  54. cout << -1;
  55. return 0;
  56. }
  57. st ="";
  58. for (int i = 0; i<a.size(); i++){
  59. // cout << a[i];
  60. st += a[i]+'0';
  61. }
  62. int zz = atoi(st.c_str());
  63. if (zz<=1000000){
  64. cout << zz;
  65. }else{
  66. cout << "-1";
  67. }
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement