fork download
  1. j#include<bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. void CollectMoney(int input1 ,char *input2)
  5. {
  6.  
  7. int arr[input1][input1];
  8. int arr1[input1*input1];
  9. int len = strlen(input2);
  10. int j=0;
  11. int num=0;
  12. int flag=0;
  13.  
  14. for(int i=0;i<len;i++)
  15. {
  16.  
  17. char c = input2[i];
  18.  
  19. if(isdigit(c))
  20. {
  21. num = num*10+ (c-'0');
  22.  
  23. }
  24. else if(i>0)
  25. {
  26. if((input2[i]==','||input2[i]==')')&&(isdigit(input2[i-1])))
  27. {
  28. arr1[j]=num;
  29. j++;
  30. num =0;
  31. }
  32.  
  33. }
  34.  
  35. }
  36.  
  37. int lim = input1*input1 ;
  38. int r = 0,c=0;
  39. for(int i=0;i<lim;i++)
  40. {
  41. if(c==input1)
  42. {
  43. c=0;
  44. r++;
  45. }
  46. arr[r][c] = arr1[i];
  47. c++;
  48. }
  49. for(int i=0;i<=input1;i++)
  50. {
  51. for(int j=0;j<=input1;j++)
  52. printf("%d ",arr[i][j]);
  53. printf("\n");
  54. }
  55.  
  56. input1--;
  57. int tc[input1][input1] ;
  58. tc[0][0] = arr[0][0];
  59.  
  60. /* Initialize first column of total cost(tc) array */
  61. for (int i = 1; i <= input1; i++)
  62. tc[i][0] = tc[i-1][0] + arr[i][0];
  63.  
  64. /* Initialize first row of tc array */
  65. for (int j = 1; j <= input1; j++)
  66. tc[0][j] = tc[0][j-1] + arr[0][j];
  67.  
  68. /* Construct rest of the tc array */
  69. for (int i = 1; i <= input1; i++)
  70. for (int j = 1; j <= input1; j++)
  71. tc[i][j] = max(tc[i-1][j], tc[i][j-1]) + arr[i][j];
  72.  
  73. printf("%d" , tc[input1][input1]);
  74.  
  75.  
  76. }
  77.  
  78.  
  79. int main()
  80. {
  81. CollectMoney(4, "'(1,7,5,2),(5,12,3,6),(100,9,23,16),(16,4,5,9)'");
  82. return 0;
  83. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:2: error: stray '#' in program
 j#include<bits/stdc++.h>
  ^
prog.cpp:1:1: error: 'j' does not name a type
 j#include<bits/stdc++.h>
 ^
prog.cpp: In function 'void CollectMoney(int, char*)':
prog.cpp:9:27: error: 'strlen' was not declared in this scope
    int len = strlen(input2);
                           ^
prog.cpp:19:20: error: 'isdigit' was not declared in this scope
        if(isdigit(c))
                    ^
prog.cpp:52:27: error: 'printf' was not declared in this scope
     printf("%d ",arr[i][j]);
                           ^
prog.cpp:53:16: error: 'printf' was not declared in this scope
     printf("\n");
                ^
prog.cpp:71:50: error: 'max' was not declared in this scope
             tc[i][j] = max(tc[i-1][j], tc[i][j-1]) + arr[i][j];
                                                  ^
prog.cpp:73:38: error: 'printf' was not declared in this scope
      printf("%d" , tc[input1][input1]);
                                      ^
prog.cpp: In function 'int main()':
prog.cpp:81:67: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  CollectMoney(4, "'(1,7,5,2),(5,12,3,6),(100,9,23,16),(16,4,5,9)'");
                                                                   ^
stdout
Standard output is empty