• 0
Sign in to follow this  
Jefte Lopes Gregorio

Dúvida com Exercício

Question

Se possível queria que resolvesse esse problema mostrado na imagem utilizando a linguagem PYTHON 3.

 

A resolução com C:

 

#include <stdio.h>

#define MAX 1001

int s[MAX];

int main(){
  int N, i, res, dif, ndif;

  scanf("%d", &N);
  for ( i = 0; i < N; i++ )
    scanf("%d", &s[i]);
  
  res = 1;
  if ( N > 1 ) dif = s[1]-s[0];

  for ( i = 1; i < N-1; i++ )
    if ( (ndif = s[i+1]-s[i]) != dif ){
      dif = ndif;
      res++;
    }
  
  printf("%d\n",res);
  
  return 0;
}

 

 

 

Resolução com C++:

 

#include <iostream>
using namespace std;

#define MAX 1001

int seq[MAX];

int main(){
  int N;
  
  cin >> N;
  for ( int i = 0; i < N; i++ )
    cin >> seq[i];
  
  int res = 1;
  
  for ( int i = 2; i < N; i++ )
    if ( seq[i]-seq[i-1] != seq[i-1]-seq[i-2] )
      res++;
  
  cout << res << endl;
  
  return 0;
}

 

ESTOU QUERENDO A RESOLUÇÃO DESSE PROBLEMA UTILIZANDO A LINGUAGEM PYTHON 3

oBI.JPG

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this