Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("sir.in");
- ofstream g("sir.out");
- int n, suma;
- char s[1001];
- struct sirfaraspatii{
- bool ok=0;
- int nr;
- };
- vector <sirfaraspatii> v;
- int sumacifrelor(int x)
- { int sum=0;
- while (x)
- { sum+=x%10;
- x=x/10;
- }
- return sum;
- }
- int main()
- {
- f.getline(s,1001);
- int lg=strlen(s);
- for (int i=0;i<lg;i++)
- { suma+=(s[i]-'0');
- cout<<3;
- /*de ce nu merge sa fac asta?*/ v[i].nr=(s[i]-'0');///pun cifrele intr-un vector separat
- cout<<4;
- }
- int suma2=0;
- int n=0;
- while (suma2!=suma)
- { n++;
- suma2+=sumacifrelor(n);
- }
- int AmGasitNrele=1;
- int contor=0;
- cout<<2;
- while (contor<v.size())
- {
- cout<<1;
- if (v[contor].nr==n%10 && v[contor].ok==0) ///verific daca se gasete numarul si nu am mai trecut pe acolo
- { int aux=n;
- aux/=10;
- int j=contor-1;
- while (v[j].nr==aux%10)
- { aux/=10;
- j--;
- }
- if (aux==0)
- { v[j].nr=n;
- v[j].ok=1;
- n--;
- while (j!=contor);
- { v.erase(v.begin()+contor);
- contor--;
- }
- }
- }
- contor++;
- }
- g<<n;
- for (int i=1;i<=v.size();i++) cout<<v[i].nr<<" "<<v[i].ok<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement