Advertisement
Johnqc

problema2,3 concurso

Jun 1st, 2018
85
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. using namespace std;
  3. struct imput {
  4. short T;
  5. short K;
  6.  
  7. };
  8. int main() {
  9.  
  10. short P, N;
  11. cin >> P>> N;
  12.  
  13. imput *Vector = new imput [P];
  14.  
  15. for (short i=0;i<P;i++){
  16. cin >>Vector[i].T >>Vector[i].K;
  17. }
  18. short *suma = new short[P];
  19. suma[0]= Vector[0].T;
  20. for (short i=1; i<P; i++){
  21. suma[i]=0;
  22. for(short vec=0; vec<=i; vec++){
  23. suma[i]+= Vector[i].T;
  24. if( Vector[vec].T == Vector[i].T) {
  25. suma[i]+= Vector[vec].T + Vector[i].T;
  26. }
  27. cout << suma[i];
  28. cout << endl;
  29. }
  30. }
  31.  
  32.  
  33. return 0;
  34. }
  35.  
  36.  
  37. ////Problema3
  38.  
  39. #include <iostream>
  40.  
  41. using namespace std;
  42.  
  43. struct Input{
  44. int K;
  45. int X;
  46. };
  47. int Collatz (int x){
  48. int f;
  49. if(x%2!=0) {
  50. f=(3*x)+1;
  51. }
  52. else if(x%2==0){
  53. f=(x/2);
  54. }
  55. return f;
  56. }
  57. int main (){
  58. int f=0, T;
  59.  
  60. cin >>T;
  61. Input *p= new Input[T];
  62. for(int i=0; i < T; i++){
  63. cin >> p[i].K >> p[i].X;
  64. }
  65. cout << endl;
  66. for (int i=0; i< T; i++){
  67.  
  68. for (int j=0 ; j<=p[i].K; j++){
  69. f = Collatz(p[i].X);
  70. p[i+1].X=f ;
  71. }
  72. cout << f << endl;
  73. }
  74.  
  75.  
  76.  
  77. return 0;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement