fork download
  1. #include<bits/stdc++.h>
  2. typedef long long ll ;
  3.  
  4. string clrstr(string str) {
  5. string cpa = "" ;
  6. bool f1 = 0 ;
  7. for(int i=0;i<str.length();i++) {
  8. if(str[i] != '0') {
  9. f1 = 1 ;
  10. }
  11. if(f1) cpa += str[i] ;
  12. }
  13. if(cpa == "") return "0" ;
  14. return cpa ;
  15. }
  16.  
  17. int compa(string stra,string strb) {
  18. int ans = 0 ;
  19. int len1 = stra.length() ;
  20. int len2 = strb.length() ;
  21. if(len1 > len2) ans = 1 ;
  22. else if(len1 < len2) ans = -1 ;
  23. if(ans == 0) {
  24. for(int i=0;i<len1;i++) {
  25. if(stra[i] > strb[i]) {
  26. ans = 1 ;
  27. break ;
  28. }
  29. else if(stra[i] < strb[i]) {
  30. ans = -1 ;
  31. break ;
  32. }
  33. }
  34. }
  35. return ans ;
  36. }
  37.  
  38. int Solution::compareVersion(string A, string B) {
  39. vector<string> vta ;
  40. string wait = "" ;
  41. char chr = '0' ;
  42. ll num ;
  43. for(ll i=0;i<A.length();i++) {
  44. chr = A[i] ;
  45. if(chr != '.') wait += chr ;
  46. else {
  47. vta.push_back(clrstr(wait)) ;
  48. wait = "" ;
  49. }
  50. }
  51. if(wait != "") {
  52. vta.push_back(clrstr(wait)) ;
  53. }
  54. // for(auto it:vta) cout << it << ' ' ;
  55. // cout << "-\n" ;
  56.  
  57.  
  58. wait = "" ;
  59. vector<string> vtb ;
  60. for(ll i=0;i<B.length();i++) {
  61. chr = B[i] ;
  62. if(chr != '.') wait += chr ;
  63. else {
  64. vtb.push_back(clrstr(wait)) ;
  65. wait = "" ;
  66. }
  67. }
  68. if(wait != "") {
  69. vtb.push_back(clrstr(wait)) ;
  70. }
  71. // for(auto it:vtb) cout << it << ' ' ;
  72. // cout << "_\n" ;
  73.  
  74.  
  75. ll mini = min(vta.size(), vtb.size()) ;
  76. int f1 = 0 ;
  77. for(ll i=0;i<mini;i++) {
  78. int ans = compa(vta[i], vtb[i]) ;
  79. // cout << ans << '_' ;
  80. if(ans != 0) {
  81. f1 = ans ;
  82. break ;
  83. }
  84. }
  85. // cout << endl ;
  86. if(f1 == 0) {
  87. if(vta.size()>vtb.size()) {
  88. for(int i=mini;i<vta.size();i++) {
  89. int ans = compa(vta[i],"0") ;
  90. f1 = ans ;
  91. }
  92. }
  93. else if(vta.size()<vtb.size()) {
  94. for(int i=mini;i<vtb.size();i++) {
  95. int ans = compa("0",vtb[i]) ;
  96. f1 = ans ;
  97. }
  98. }
  99. }
  100. return f1;
  101. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
321.324.63
12.0.0.1
compilation info
prog.cpp:4:1: error: ‘string’ does not name a type; did you mean ‘stdin’?
 string clrstr(string str) {
 ^~~~~~
 stdin
prog.cpp:17:11: error: ‘string’ was not declared in this scope
 int compa(string stra,string strb) {
           ^~~~~~
prog.cpp:17:11: note: suggested alternative:
In file included from /usr/include/c++/8/iosfwd:39,
                 from /usr/include/c++/8/ios:38,
                 from /usr/include/c++/8/istream:38,
                 from /usr/include/c++/8/sstream:38,
                 from /usr/include/c++/8/complex:45,
                 from /usr/include/c++/8/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::string’
   typedef basic_string<char>    string;
                                 ^~~~~~
prog.cpp:17:23: error: ‘string’ was not declared in this scope
 int compa(string stra,string strb) {
                       ^~~~~~
prog.cpp:17:23: note: suggested alternative:
In file included from /usr/include/c++/8/iosfwd:39,
                 from /usr/include/c++/8/ios:38,
                 from /usr/include/c++/8/istream:38,
                 from /usr/include/c++/8/sstream:38,
                 from /usr/include/c++/8/complex:45,
                 from /usr/include/c++/8/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::string’
   typedef basic_string<char>    string;
                                 ^~~~~~
prog.cpp:17:34: error: expression list treated as compound expression in initializer [-fpermissive]
 int compa(string stra,string strb) {
                                  ^
prog.cpp:38:5: error: ‘Solution’ has not been declared
 int Solution::compareVersion(string A, string B) {
     ^~~~~~~~
prog.cpp:38:30: error: ‘string’ was not declared in this scope
 int Solution::compareVersion(string A, string B) {
                              ^~~~~~
prog.cpp:38:30: note: suggested alternative:
In file included from /usr/include/c++/8/iosfwd:39,
                 from /usr/include/c++/8/ios:38,
                 from /usr/include/c++/8/istream:38,
                 from /usr/include/c++/8/sstream:38,
                 from /usr/include/c++/8/complex:45,
                 from /usr/include/c++/8/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::string’
   typedef basic_string<char>    string;
                                 ^~~~~~
prog.cpp:38:40: error: ‘string’ was not declared in this scope
 int Solution::compareVersion(string A, string B) {
                                        ^~~~~~
prog.cpp:38:40: note: suggested alternative:
In file included from /usr/include/c++/8/iosfwd:39,
                 from /usr/include/c++/8/ios:38,
                 from /usr/include/c++/8/istream:38,
                 from /usr/include/c++/8/sstream:38,
                 from /usr/include/c++/8/complex:45,
                 from /usr/include/c++/8/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
                 from prog.cpp:1:
/usr/include/c++/8/bits/stringfwd.h:74:33: note:   ‘std::__cxx11::string’
   typedef basic_string<char>    string;
                                 ^~~~~~
prog.cpp:38:48: error: expression list treated as compound expression in initializer [-fpermissive]
 int Solution::compareVersion(string A, string B) {
                                                ^
stdout
Standard output is empty