Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- S20 / 2020
- SIII ex 1
- #include <iostream>
- using namespace std;
- int transformareBaza10(int b,int n)
- {
- int s=0,k=0,p=1;
- while(n!=0)
- {
- int c=n%10;
- s=s+c*p;
- p=p*b;
- n=n/10;
- }
- return s;
- }
- int main()
- {
- int b,n;
- cin>>b>>n;
- cout<<transformareBaza10(b,n);
- return 0;
- }
- SIII ex 2
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char s[101], *t, aux[101]={0}, cuv[101],*p;
- int poz;
- cin.get(s,101);
- t=strtok(s, " ");
- while(t){
- poz=-1;
- strcpy(cuv,t);
- p=strchr(cuv,',');
- /** if(p!=NULL){
- poz=(cuv+poz)-(cuv+0);
- cout<<p<<" "<<poz<<endl;
- cuv[poz]='\0';
- }
- */
- for(int i=0;i<strlen(cuv);i++){
- if(cuv[i]==',') poz=i;
- }
- if(poz!=-1) cuv[poz]='\0';
- strcat(aux,cuv);
- strcat(aux, " ");
- t=strtok(NULL, " ");
- }
- strcpy(s,aux);
- cout<<s;
- return 0;
- }
- SIII ex 3
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- int s=0,smax=0,x,y;
- cin>>x;
- s=s+x;
- while(cin>>y){
- if(x%2==y%2){
- s=s+y;
- }else{
- if(s>smax){
- smax=s;
- }
- s=y;
- }
- x=y;
- }
- if(s>smax){
- smax=s;
- }
- cout<<smax;
- return 0;
- }
- SII
- 1.
- 1 12 13
- 2 6
- 3 4 7
- SI
- 2. f(3)
- r=0
- i=1 r=0+1+f(2)=5
- i=2 r=r+2+f(1)=5+2+1=8
- i=3 r=r+3+f(0)=8+3=11
- f(0)=0
- f(1)=1
- f(2)=4
- r=0
- i=1 r=0+1+f(1)=2
- i=2 r=2+2+f(0)=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement