Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- int alg(int* sequencia, int valor, int tamanho) {
- int soma;
- for(int i = 0; i < tamanho; i++){
- for(int j = i; j < tamanho; j++){
- soma = 0;
- for (int z = i; z <= j; z++){
- soma = soma + sequencia[z];
- }
- if(soma == valor){
- return i;
- }
- }
- }
- return -1;
- }
- int main() {
- int tamanho;
- int valor;
- int numero;
- //int sequencia[10000];
- int resultado;
- while(1) {
- scanf("%d %d", &tamanho, &valor);
- if(tamanho == 0 && valor == 0){
- exit(0);
- }
- else {
- int sequencia[tamanho];
- for(int i = 0; i < tamanho; i++){
- scanf("%d", &numero);
- sequencia[i] = numero;
- }
- resultado = alg(sequencia, valor, tamanho);
- if (resultado != -1) {
- printf("SUBSEQUENCIA NA POSICAO %d\n", resultado+1);
- }
- else {
- printf("SUBSEQUENCIA NAO ENCONTRADA\n");
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement