Advertisement
rotti321

T20 2020

May 31st, 2021
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. S20 / 2020
  2.  
  3. SIII ex 1
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. int transformareBaza10(int b,int n)
  9. {
  10.     int s=0,k=0,p=1;
  11.     while(n!=0)
  12.     {
  13.         int c=n%10;
  14.         s=s+c*p;
  15.         p=p*b;
  16.         n=n/10;
  17.     }
  18.     return s;
  19. }
  20. int main()
  21. {  
  22.     int b,n;
  23.     cin>>b>>n;
  24.     cout<<transformareBaza10(b,n);
  25.     return 0;
  26. }
  27.  
  28.  
  29. SIII ex 2
  30. #include <iostream>
  31. #include <cstring>
  32. using namespace std;
  33.  
  34. int main()
  35. {  
  36.     char s[101], *t, aux[101]={0}, cuv[101],*p;
  37.     int poz;
  38.     cin.get(s,101);
  39.     t=strtok(s, " ");
  40.     while(t){
  41.         poz=-1;
  42.         strcpy(cuv,t);
  43.         p=strchr(cuv,',');
  44.       /**  if(p!=NULL){
  45.            
  46.             poz=(cuv+poz)-(cuv+0);
  47.             cout<<p<<" "<<poz<<endl;
  48.             cuv[poz]='\0';
  49.         }
  50.         */
  51.         for(int i=0;i<strlen(cuv);i++){
  52.             if(cuv[i]==',') poz=i;
  53.         }
  54.         if(poz!=-1) cuv[poz]='\0';
  55.      
  56.         strcat(aux,cuv);
  57.         strcat(aux, " ");
  58.         t=strtok(NULL, " ");
  59.     }
  60.     strcpy(s,aux);
  61.     cout<<s;
  62.     return 0;
  63. }
  64.  
  65. SIII ex 3
  66. #include <iostream>
  67. #include <cstring>
  68. using namespace std;
  69.  
  70. int main()
  71. {  
  72.     int s=0,smax=0,x,y;
  73.     cin>>x;
  74.     s=s+x;
  75.     while(cin>>y){
  76.         if(x%2==y%2){
  77.             s=s+y;
  78.         }else{
  79.             if(s>smax){
  80.                 smax=s;
  81.             }
  82.             s=y;
  83.         }
  84.         x=y;
  85.     }
  86.     if(s>smax){
  87.         smax=s;
  88.     }
  89.     cout<<smax;
  90.    
  91.     return 0;
  92. }
  93.  
  94. SII
  95. 1.
  96. 1   12  13
  97. 2   6
  98. 3   4   7
  99.  
  100. SI
  101. 2. f(3)  
  102.     r=0
  103. i=1 r=0+1+f(2)=5
  104. i=2 r=r+2+f(1)=5+2+1=8
  105. i=3 r=r+3+f(0)=8+3=11
  106.  
  107. f(0)=0
  108. f(1)=1
  109.  
  110. f(2)=4
  111.     r=0
  112. i=1 r=0+1+f(1)=2
  113. i=2 r=2+2+f(0)=4
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement