Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ofstream fout("BAC.TXT");
- /*
- toate numerele de 5 cifre
- suma primelor 2=s1
- suma ultimelor 2=s2
- */
- struct pereche
- {
- int prim, ult;
- }nr1[10], nr2[10];
- int main()
- {
- int s1, s2; cin>>s1>>s2;
- int cnt1=0, cnt2=0;
- ///determinare perechi convenabile
- int stop; stop=min(9, s1);
- /* am grija unde ma opresc
- sa nu trec pe valori negative*/
- for (int i=1; i<=stop; i++)
- {//prima cifra nu poate fi 0
- if (s1-i<10)//vreau doar cifre, nu numere
- {
- ++cnt1;
- nr1[cnt1].prim=i;
- nr1[cnt1].ult=s1-i;
- }
- }
- stop=min(9, s2);
- for (int j=0; j<=stop; ++j)
- {
- if (s2-j<10)
- {
- ++cnt2;
- nr2[cnt2].prim=j;
- nr2[cnt2].ult=s2-j;
- }
- }
- ///
- int val;
- /*efectiv formez numerele
- prima data derulez cifrele de ordin mai mic
- pentru a pastra ordinea crescatoare*/
- for (int i=1; i<=cnt1; ++i)//maxim 11 cred
- {
- for (int k=0; k<=9; ++k) //10
- {
- for (int j=1; j<=cnt2; ++j) //tot pe acolo
- {
- val=nr2[j].ult+nr2[j].prim*10+k*100+nr1[i].ult*1000+nr1[i].prim*10000;
- fout<<val<<'\n';
- }
- }
- }
- ///rezulta o complexitate aproximativa de 10^3
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment