TOPIC

PROBLEM 1185 - URI Fórum 1.0

beecrowd asked on Feb 8 2013

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • dwfdsouza replied 8 years ago

    Por favor alguém pode me ajudar?? Não sei pq mas dá WR100% e testei aqui uns casos e deram certo, desde já grato

    Obrigado!! Resolvido
  • ggroth replied 9 years ago

    A condição do for sempre será falsa

    for(c=11-l;c<0;c--){

    Porque c nunca será menor que zero ;). Inverte o sinal de "<" que ao menos você consegue testar os valores (de soma ou média) para verificar se estão corretos...

  • dwfdsouza replied 8 years ago

    Tinha lido "Average' :P irei prestar mais atenção nisso, v@leu!

  • Joao40 replied 8 years ago

    A média tem que ser calculada quando digitar 'M' e não 'A'.

  • clmcosta replied 8 years ago

    Nao consigo encontrar o erro, ja fiz varios teste e smp da WA 100%

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char operacao;
        double soma = 0, media = 0, matriz [12][12];
        int i, j;
    
        scanf ("%c", &operacao);
    
        if (operacao == 'M')
        {
            for (i = 0; i < 12; i++)
            {
                for (j = 0; j < 11 - i; j++)
                {
                    scanf ("%lf", &matriz [i][j]);
                    soma += matriz [i][j];
                }
            }
            media = soma/66;
            printf ("%.1lf", media);
        }
        else if (operacao == 'S')
        {
            for (i = 0; i < 12; i++)
            {
                for (j = 0; j < 11 - i; j++)
                {
                    scanf ("%lf", &matriz [i][j]);
                    soma += matriz [i][j];
                }
            }
            printf ("%.1lf", soma);
        }
    
        system("PAUSE");
        return 0;
    }
  • Deniskawasaki replied 8 years ago

    Nao estou achando o erro neste meu codigo... quem puder me ajudar ficaria grato. import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.text.DecimalFormat; public class Main {

    public static void main(String[] args) throws IOException {
    InputStreamReader ir = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(ir);
    DecimalFormat f = new DecimalFormat(".0");
    int cont=0;
    int i = 1;
    double soma=0;
    double media=0;
    double X;
    double m [][] = new double [5][5];
    String O = in.readLine();
        for(int linha=0;linha<m.length;linha++){
            for(int coluna=0;coluna<m[0].length;coluna++){
                X= Double.parseDouble(in.readLine());
                m[linha][coluna]=X;
            }
        }       
            if (O.equals("S")){
                for(int linha = 0;linha<m.length-1;linha++){
                    for(int coluna=0;coluna<=m.length-i;coluna++){
                        soma+=m[linha][coluna];
                        System.out.println(">>" + soma);
                    }
                }
                System.out.println(f.format(soma));
            }
            else if(O.equals("M")){
                for(int linha = 0;linha<m.length;linha++){           
                    for(int coluna=0;coluna<m.length-i;coluna++){
                        soma+=m[linha][coluna];
                    }
    
                }
                media=soma/10;
                System.out.println(f.format(media));
            }
    }

    }

  • iadsmorandin replied 8 years ago

    Olá, preciso de ajuda. Segui a lógica dos problemas anteriores, fiz testes no toolkit fechou os resultados dos testes. Utilizei à função Soma e em seguida a função Média do programa com números de 1 à 144, tanto no toolkit quanto no meu programa o resultado foi o mesmo, porém o portal me deu WA(100%). segue o código, caso alguém possa me ajudar:

    include

    include

    using namespace std;

    int main() { double M[12][12],soma=0; int c=0,l=0,d=0; char op; cin >> op; while(l<=11 && c<=11){ cin >>M[l][c]; c++; if (c==12){ l++; c=0; } } c=0; l=11-(c+1); while(l>=-1 && c<=11){ soma=soma+M[l][c]; l--; if (l==-1){ c++; l=11-(c+1); } d++; } d--; cout << fixed<<setprecision(1); if (op=='S'){ cout <<soma<<endl; }else if (op=='M'){ cout <<soma/d<<" "<<d<<endl; }

    return 0;

    }

  • jjulian replied 9 years ago

    O que ha de errado com o código? agradeco

    #include <stdio.h>
    #include <stdlib.h>
    
    float Average(int mat[][12]){
        int i, j, count, sum = 0;
        float average;
        count = 0;
        for (i=0; i<11;i++){
            for (j=0; j<11-count; j++){
                sum = sum + mat[i][j];
            }
            count++;
        }
        average = sum/50;
        //printf("%d", sum);
        return average;
    
    }
    int Sum(int mat[][12]){
        int i, j, count, sum = 0;
        count = 0;
        for (i=0; i<11;i++){
            for (j=0; j<11-count; j++){
                sum = sum + mat[i][j];
            }
            count++;
        }
        //printf("%d", sum);
        return sum;
    }
    
    int main(int argc, const char * argv[]) {
        int mat[12][12], i, j;
        char option;
    
        for (i=0; i<12; i++){
            for (j=0; j<12; j++){
                mat[i][j] = rand()%100 + 1;
            }
        }
        //choose S or M
        scanf("%c", &option);
        if (option == 'S'){
            Sum(mat);
    
        }
        else if (option == 'M'){
            Average(mat);
        }
        else{
            printf("u've entered a wrong character");
        }
        return 0;
    }
  • Nathalia4 replied 9 years ago

    #include <stdio.h>
    
    int main(void) {
    
    double m[12][12];
    double soma = 0, media = 0;
    char op;
    int c, l;
    scanf("%c", &op);
    
    for(l=0;l<12;l++){
        for(c=0; c<12; c++){
            scanf("%lf", &m[l][c]);
        }
    }
    if (op == 'S'){
        for(l=0;l<12;l++){
            for(c=11-l;c<0;c--){
                soma += m[l][c];
            }
        }
        printf("%.1lf\n", soma);
    }
    
     if (op == 'M'){
            for(l=0;l<12;l++){
            for(c=11-l;c<0;c--){
                soma += m[l][c];
                media = soma/66;
            }
        }
        printf("%.1lf\n", media);
    }
    
        return 0;
    }
  • ggroth replied 9 years ago

    Cara, teu código nem está compilando...

    Obs: Sempre que postar seus códigos, utilize as tags code para manter o fórum organizado...

  • ftrmendonca replied 9 years ago

    Tá dando o mesmo resultado do toolkit

    include

    include

    include

    include

    using namespace std;

    int main() { char op = 'a'; double matriz[12][12], media, soma; int cont = 0, cu = 11;

    soma = media = 0;
    
    cin >> op;
    
    for (int x = 0; x < 12; x++)
    {
        for (int y = 0; y < 12; y++)
        {
           cin >> matriz[x][y];
        }
    }
    
    for (int x =0; x < 11; x++)
    {
        for (int y = 0; y < cu && cu >= 1; y++)
        {
            soma+= matriz[x][y];
            cont++;
        }
    
        cu--;
    }
    
    if(op == 'M')
    printf("%.1f\n", soma/media);
    
    if (op == 'S')
    printf("%.1f\n", soma);
    
    return 0;

    }

  • ggroth replied 9 years ago

    Eu não disse que o problema era na variável assist, mas sim em um dos laços for em volta dela ;) A tua variável soma tem que acumular os valores acima da diagonal principal, mas não é isso que está fazendo...

    Bom, gerei um caso de teste para que você possa testar o teu algoritmo:

    S
    2.6
    3.7
    3
    8.8
    9.4
    4.5
    2.8
    1.1
    2
    7.9
    2.6
    3.4
    6.1
    9
    3
    4
    8.3
    0.6
    9.7
    6.3
    8.5
    0.8
    0.9
    4
    5.8
    1.1
    7.4
    4.5
    7.9
    4.2
    5.2
    5.7
    3.2
    8.3
    9.8
    2.6
    2.8
    2.6
    8.9
    0.1
    0.5
    1.6
    3.5
    1.9
    5.8
    6.5
    1.1
    9.4
    2.4
    6
    0.9
    0.9
    6.8
    1.8
    0.2
    2.7
    8.1
    7.6
    2.4
    6.1
    7.1
    7.6
    7
    0.3
    1.1
    2
    8.1
    9.2
    9.8
    7
    9.3
    0.4
    3.8
    8
    7.5
    9.7
    9.8
    8.6
    9.1
    2.2
    9.8
    0
    8.3
    6.6
    7.1
    3.7
    4.5
    5.2
    6.6
    6.9
    6.5
    3.7
    9.8
    8.8
    9.2
    0.9
    0.8
    7.3
    0.1
    0.7
    9.5
    4.6
    6.3
    3.4
    2.7
    3.8
    8.3
    7.7
    7.6
    2.6
    5.1
    7.4
    7.8
    3.4
    9.2
    4.9
    2.4
    3.8
    5.4
    9
    5.9
    1.9
    7.9
    5.7
    0.7
    7.1
    1.9
    6.8
    9.6
    7.2
    2.7
    4.3
    1.9
    9
    2.9
    9.8
    8
    6.4
    7.5
    0.8
    9
    2.6
    8.2
    6.9

    Output:

    299.3
  • lpmuniz replied 9 years ago

    Removi a variável assist, configurei a variável soma para entregar o resultado desejado e arrumei o problema do compilation error. Agora está correto ou ainda há erros?

    #include <stdio.h>
    #include <stdlib.h>
    
    #define L 12
    #define C 12
    
    int main (){
       double M[L][C];
       int i,j;
       char T;
       double soma, media;
    
       scanf("%c",&T);
    
       for (i=0;i<L;i++){
          for(j=0;j<C;j++){
             scanf("%lf",&M[i][j]);
          }
       }
    
       for (i=0;i<L;i++) {
          for(j<C;j=0;j--) {
          }
       }
    
       if(T=='S'){
          soma+=M[i][j];
          printf("%.1lf\n",soma);
       }else if(T=='M'){
          media=soma/assist;
          printf("%.1lf\n",media);
       }
    
       return 0;
    }
  • ggroth replied 9 years ago

    Cara, teu código está dando erro de compilação. Além disso, tua variável soma vai ser sempre 0, e há um pequeno problema no segundo conjunto de for (onde você usa a variável assist). Conserte esses problemas e teste com alguns valores para confirmar se está tudo certo ;)

  • lpmuniz replied 9 years ago

    Onde está errado?

    #include <stdio.h>
    #include <stdlib.h>
    
    #define L 12
    #define C 12
    
    int main (){
       double M[L][C];
       int i,j,assist=0;
       char T;
       double soma=0,media=0;
    
       scanf("%c",&T);
    
       for (i=0;i<L;i++){
          for(j=0;j<C;j++){
             scanf("%lf",&M[i][j]);
          }
       }
    
       for (i=0;i<L;i++){
          for(j<C;j=0;j--){
                assist++;      
             }   
          }
       }
    
       if(T=='S'){
          printf("%.1lf\n",soma);
       }else if(T=='M'){
          media=soma/assist;
          printf("%.1lf\n",media);
       }
    
       return 0;
    }
  • ggroth replied 9 years ago

    Agora está assim

    0 1 1 1 1 1 1 1 1 1 1 0 
    0 1 1 1 1 1 1 1 1 1 0 0 
    0 1 1 1 1 1 1 1 1 0 0 0 
    0 1 1 1 1 1 1 1 0 0 0 0 
    0 1 1 1 1 1 1 0 0 0 0 0 
    0 1 1 1 1 1 0 0 0 0 0 0 
    0 1 1 1 1 0 0 0 0 0 0 0 
    0 1 1 1 0 0 0 0 0 0 0 0 
    0 1 1 0 0 0 0 0 0 0 0 0 
    0 1 0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 0 0
  • ssoares0 replied 9 years ago

    Agora está certo??

    Obrigado!!!!!!!!!!!!!!!!!!!!!!!!!!!
  • amesquita replied 9 years ago

    na condição do 2º for vc colocou j < 0 e no caso deveria ser j > 0. ;)

  • ggroth replied 9 years ago

    Tem certeza de que está somando apenas acima da diagonal? Abaixo está a matriz, com valor 1 todos os que você está utilizando para a soma

    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    1 1 1 1 1 1 1 1 1 1 1 0 
    0 0 0 0 0 0 0 0 0 0 0 0
  • ssoares0 replied 9 years ago

    POR QUE WA?? Onde está o erro?

    #include <stdio.h>
    
    #define MAX 12 
    int main(){
    
    int C,i,j,n=0,p=11;
    float M[MAX][MAX],soma=0;
    char t;
        scanf("%c", &t);
        for(i=0;i<MAX;i++){
            for(j=0;j<MAX;j++){
                scanf("%f", &M[i][j]);
            }
        }
        for(j=10;j>=0;j--){
                for(i=0;i<11;i++){
                soma+=M[i][j];              
    
    }
    }
        if(t=='S'){printf("%.1f\n",soma);}
        else{ printf("%.1f\n",soma/66);}
    }
1 of 2