Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int q,qinvers[12],p[10005],x[10005],n,k,cifre[10];
  6. int modif[10005], s[105],d[105];
  7. ifstream f("mostenire.in");
  8. ofstream g("mostenire.out");
  9.  
  10. void cerinta1()
  11. {
  12. int i,j;
  13. for(i=1; i<=n; i++)
  14. f>>x[i];
  15. for(i=1; i<=k; i++)
  16. f>>s[i]>>d[i];
  17. for (i=k; i>=1; i--)
  18. {
  19. for(j=s[i]; j<=d[i]; j++)
  20. x[j]=qinvers[x[j]];
  21.  
  22. }
  23. for(i=1; i<=n; i++)
  24. g<<x[i]<<" ";
  25. g<<endl;
  26. }
  27. void cerinta2()
  28. {
  29. int i,j, tmax=0,z=0,cif;
  30. for(i=1; i<=n; i++)
  31. f>>p[i];
  32. for(i=1; i<=k; i++)
  33. f>>s[i]>>d[i];
  34. for(i=1; i<=k; i++)
  35. for(j=s[i]; j<=d[i]; j++)
  36. modif[j]++;
  37. for(i=1; i<=n; i++)
  38. if(modif[i]>tmax)
  39. {
  40. tmax=modif[i];
  41. z=i;
  42. }
  43. cif=p[z];
  44. cifre[cif]=1;
  45. for(i=k; i>=1; i--)
  46. if( s[i]<=z && z<=d[i])
  47. {
  48. cif=qinvers[cif];
  49. cifre[cif]=1;
  50. }
  51.  
  52. g<<z<<endl;
  53. for(i=1; i<=9; i++)
  54. if(cifre[i])g<<i<<" ";
  55. g<<endl;
  56. }
  57.  
  58. int main()
  59. {
  60. int cer,i;
  61. f>>cer>>q>>n>>k;
  62. for(i=9; i>=1; i--)
  63. {
  64. qinvers[q%10]=i;
  65. q=q/10;
  66. }
  67. if(cer==1) cerinta1();
  68. else cerinta2();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement