Advertisement
a53

tabel1

a53
Feb 4th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f ("tabel1.in");
  7. ofstream g ("tabel1.out");
  8.  
  9. int val['z' + 1],apare[12],n,k,j,s,i,y;
  10. char x;
  11.  
  12. int main()
  13. {
  14. f >> n;
  15. for(i = 1; i <= n; i++)
  16. {
  17. f >> x >> y;
  18. val[x] = y;
  19. }
  20.  
  21. while(f >> x)
  22. if(isdigit(x)) // daca e cifra
  23. apare[x - '0']++; // vector de freventa in care contorizez cifrele care apar
  24. else if(val[x]) // daca e litera si a fost modificata in tabel
  25. s += val[x] ; // adaug la suma
  26. else s += x; // daca e litera si nu a fost modificata,adaug la suma
  27.  
  28. g << s << '\n';
  29.  
  30. for(i = 0;i <= 9;i++)
  31. if(apare[i])
  32. k++;
  33. // am contorizat cate cifre am in sir
  34.  
  35. for(i = 9,j = 1;j <= k / 2;i--)
  36. if(apare[i])
  37. g << i,j++;
  38. // afisez prima jumatate din numarul deal-vale
  39. if(k % 2 == 0)
  40. j = 1;
  41. else j = 0;
  42.  
  43. for(i = 0;j <= k / 2;i++)
  44. if(apare[i])
  45. g << i,j++;
  46. // afisez a doua jumatate din numarul deal-vale
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement