c# 3.0 - When I am trying to give input the input line trimmed to 88 digits -


when run program input of 100 trimmed enter lines upto 88 , gives array out of bound exception.i.e. take upto 5 these nos. ( 50 33 11 27 19 40 13 27 37 45 40) not displayed on console window

    using system;      using system.numerics;     class myclass {     static void main(string[] args) {     int t = convert.toint32(console.readline());         string worth =console.readline();         string[] worthsplit = new string[t];         int[] worthtransactions = new int[t];         int sum=0;         int q = convert.toint32(console.readline());         int[] target = new int[q];         (int = 0; < q; i++)         {             target[i]=convert.toint32(console.readline());         }         if (t >= 1 && t <= 100000 && q >= 1 && q <= 1000000)         {             worthsplit = worth.split(' ');             (int = 0; < t; i++)             {                 worthtransactions[i] = convert.toint32(worthsplit[i]);             }             (int j = 0; j < q; j++)             {                 sum = 0;                 int k = 0;                 while (target[j] > sum && k<t)                 {                     sum+=worthtransactions[k];                     k++;                 }                 if (k >= t)                 {                     console.writeline("-1");                 }                 else                 {                     console.writeline(k);                 }             }         }  } 

}

     input:        100      34 37 28 16 44 36 37 43 50 22 13 28 41 10 14 27 41 27 23 37 12 19 18 30         33 31 13 24 18 36 30 3 23 9 20 18 44 7 12 43 30 24 22 20 35 38 49 25 16 21 14 27 42 31 7 24 13 21 47 32 6 26 35 28 37 6 47 30 14 8 25 46 33 46 15 18 35 15 44 1 38 9 27 29 39 35 4 2 5 50 33 11 27 19 40 13 27 37 45 40       90      2634      2633      2632      2631      2630      2629      2628      2627      2626      2625      2624      2623      2622      2621      2620      2619      2618      2617      2616      2615      2614      2613      2612      2611      2610      2609      2608      2607      2606      2605      2604      2603      2602      2601      2600      2599      2598      2597      2596      2595      2594      2593      2592      2591      2590      2589      2588      2587      2586      2585      2584      2583      2582      2581      2580      2579      2578      2577       2576      2575      2574      2573      2572      2571      2570      2569      2568      2567      2566      2565      2564      2563 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -