fork download
  1. // pwgen pentru RST
  2. // realizat de : alexalghisi
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string.h>
  6. #include <cmath>
  7. #include <vector>
  8. #include <ctime>
  9. using namespace std;
  10.  
  11. string cs;
  12. int x;
  13. vector<char> v;
  14. vector<int> poz;
  15. char nume[20];
  16. struct HUGE{int x[100];};
  17. HUGE rez;
  18. time_t secondsvechi,secondsnou;
  19.  
  20. char *Read()
  21. {
  22. cout<<"---------------------------------------------------------------------\n";
  23. cout<<"| Introduceti numele fisierului in care se vor salva parolele : ";
  24. cin.getline(nume, 100);
  25. return nume;
  26. }
  27.  
  28.  
  29. ofstream g(Read());
  30.  
  31. vector<int> adun(vector<int> &a )
  32. {
  33. vector<int> b(1,1);
  34. vector<int> c;
  35. int t=0;
  36. for(unsigned int i=0;i<a.size() || i<b.size() || t>0;i++)
  37. {
  38. int x=(i<a.size())?a[i]:0;
  39. int y=(i<b.size())?b[i]:0;
  40. c.push_back((x+y+t)%10);
  41. t=(x+y+t)/10;
  42. }
  43. return c;
  44. }
  45. bool modulo(vector<int> &m)
  46. {
  47. for(int i=0;i<=5;i++)
  48. if(m[i]!=0)
  49. return false;
  50. return true;
  51. }
  52.  
  53. void afisez(vector<int> &m)
  54. {
  55. for(int i=m.size()-1;i>=0;i--)
  56. printf("%d",m[i]);
  57. return;
  58. }
  59.  
  60. void pr(int niv)
  61. {
  62. if(niv==x)
  63. {
  64. poz=adun(poz);
  65.  
  66. for(unsigned int i=0;i<v.size();i++)
  67. g<<v[i];
  68. g<<"\n";
  69.  
  70. if(modulo(poz))
  71. {
  72. secondsnou = time (NULL);
  73. cout<<"Au fost generate ";
  74. afisez(poz);
  75. cout<<" cuvinte , in :" ;
  76. cout<<( secondsnou-secondsvechi )<<" secunde ";
  77. cout<<"\n";
  78. secondsvechi = time(NULL);
  79. }
  80. return;
  81. }
  82. for(unsigned int i=0;i<cs.size();i++)
  83. {
  84. v.push_back(cs[i]);
  85. pr(niv+1);
  86. v.pop_back();
  87. }
  88. }
  89.  
  90. HUGE AtribValue(unsigned long long X)
  91. {
  92. HUGE H;
  93. H.x[0] = 0;
  94. while (X)
  95. {
  96. ++H.x[0];
  97. H.x[H.x[0]] = X % 10;
  98. X /= 10;
  99. }
  100. return H;
  101. }
  102. HUGE produs(HUGE A, HUGE B)
  103. /* C <- A x B */
  104. {
  105. HUGE C;
  106. int i,j,T=0;
  107.  
  108. C.x[0]=A.x[0]+B.x[0]-1;
  109. for (i=1;i<=A.x[0]+B.x[0];) C.x[i++]=0;
  110. for (i=1;i<=A.x[0];i++)
  111. for (j=1;j<=B.x[0];j++)
  112. C.x[i+j-1]+=A.x[i]*B.x[j];
  113. for (i=1;i<=C.x[0];i++)
  114. { T=(C.x[i]+=T)/10;
  115. C.x[i]%=10;
  116. }
  117. if (T) C.x[++C.x[0]]=T;
  118. return C;
  119. }
  120.  
  121.  
  122.  
  123. HUGE put(int baza,int putere)
  124. {
  125. if(putere==0)
  126. {
  127. HUGE zero;
  128. zero.x[0]=1;
  129. zero.x[1]=1;
  130. return zero;
  131. }
  132. if(putere==1)
  133. return AtribValue(baza);
  134. if(putere%2==0)
  135. {
  136. HUGE X=put(baza,putere/2);
  137. return produs(X,X);
  138. }
  139.  
  140. return produs(AtribValue(baza),put(baza,putere-1));
  141. }
  142.  
  143. HUGE Divide(HUGE A, int X)
  144. {
  145. int i;
  146. unsigned long R=0;
  147.  
  148. for (i=A.x[0];i;i--)
  149. { A.x[i]=(R=10*R+A.x[i])/X;
  150. R%=X;
  151. }
  152. while (!A.x[A.x[0]] && A.x[0]>1) A.x[0]--;
  153. return A;
  154. }
  155.  
  156.  
  157. int main()
  158. {
  159. cout<<"| Introduceti caracterele din care sa fie compuse cuvintele : ";
  160.  
  161. getline(cin,cs);
  162.  
  163. cout<<"| Introduceti lungimea cuvintelor : ";
  164. cin>>x;
  165. cout<<"| Numarul de parole care vor fi generate : ";
  166. rez=put(cs.size(),x);
  167. for(int i=rez.x[0];i>=1;i--)
  168. cout<<rez.x[i];
  169.  
  170. // Urmatoarele sunt doar de test
  171.  
  172. HUGE memorie=rez;
  173.  
  174. cout<<"\n| Spatiu ocupat aproximativ : "; // memorie ocupata
  175. memorie=produs(memorie,AtribValue(x+2));
  176. memorie=Divide(memorie,1024);
  177. memorie=Divide(memorie,1024);
  178. for(int i=memorie.x[0];i>=1;i--)
  179. cout<<memorie.x[i];
  180. cout<<" MB";
  181.  
  182.  
  183. cout<<"\n| Timpul mediu necesar : "; // timp necesar
  184. rez=Divide(rez,166666); // procesor mediu
  185. rez=Divide(rez,60);
  186.  
  187. for(int i=rez.x[0];i>=1;i--)
  188. cout<<rez.x[i];
  189.  
  190. cout<<" minute";
  191. cout<<"\n| Continuam ? (Y/N) :";
  192. char ch;
  193. cin>>ch;
  194.  
  195. if(ch=='Y' || ch=='y')
  196. {
  197. printf("\nSe genereaza ...\n");
  198. secondsvechi = time (NULL);
  199. pr(0);// genereaza
  200. printf("Au fost generate : " );
  201. afisez(poz);
  202. printf(" parole ");
  203. printf("\nAm terminat :)");
  204. }
  205. return 0;
  206. }
  207.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16: error: expected identifier before numeric constant
prog.cpp:16: error: expected unqualified-id before numeric constant
prog.cpp:17: error: expected unqualified-id before numeric constant
prog.cpp:90: error: expected unqualified-id before numeric constant
stdout
Standard output is empty