Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

WA in KAN13C

$
0
0

Can u explain why this code is giving WA

include <stdio.h> include <stdlib.h> include <string.h> int main() { char str = (char ) malloc(4 * 1000000 * sizeof(char)); int asv = (int ) malloc(4 * 1000000 * sizeof(int)); long long int i; long long int j; long long int k; long long int l;

while (1) { scanf("%s", str);

   if (strcmp(str,"End") == 0)
        break;

   k = strlen(str);

   l = 0;

   for (i = 1; i < k; ++i) {
       if (str[i] == str[0])
           asv[i] = 1;
        else
            asv[i] = 0;
   }

   for (i = 1; i < k; ++i) {
         if (asv[i-1] >= 1 && asv[i-1] <= 9) {
            j = asv[i-1];
            if (str[i] == str[j]) {
               asv[i] = j + 1;
            }
         }
    }

   for (i = 0; i < k; ++i)
       printf("%d ", asv[i]);

   printf("\n");

}

free(asv); free(str); return 0; } It is working fine for all cases in my system. Ideone link is :-- http://ideone.com/vV6bYl Thnx in advance


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>