fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. string str="-5e^3+8e^4i";
  10. string str2=str;
  11. string a;
  12. for(int i=0;i<str2.length();i++){
  13. a=to_string(str2.at(i));
  14. if(a=="e")
  15. str2.replace(i,1,"+");
  16.  
  17. }
  18.  
  19.  
  20. bool twoItems=false;
  21. bool eAll=false;
  22.  
  23. for(int i=1;i<str.length();i++){
  24. a=to_string(str2.at(i));
  25. if(a== "+" || a=="-")
  26. twoItems=true;
  27. if(a=="e")
  28. eAll=true;
  29. }
  30. // your code goes here
  31. bool e1,e2,isi;
  32. e1=false;
  33. e2=false;
  34.  
  35.  
  36.  
  37. for(int i=0;i<str.length();i++){
  38. a=to_string(str2.at(i));
  39. if(a=="i")
  40. isi==true;
  41. }
  42.  
  43.  
  44. if(twoItems){
  45.  
  46.  
  47. string s1=str.substr(1,str.find("+","-"));
  48. string s2=str.substr(str.find("+","-"), str.length());
  49.  
  50.  
  51. for(int i=0;i<s1.length();i++){
  52. a=to_string(str2.at(i));
  53. if(a=="e"){
  54. e1=true;
  55. s1.replace(i,1,"e");
  56. }
  57. }
  58.  
  59. for(int i=0;i<s2.length();i++){
  60. a=to_string(str2.at(i));
  61. if(a=="e"){
  62. e2=true;
  63. s2.replace(i,1,"e");
  64. }
  65. }
  66. }
  67.  
  68.  
  69.  
  70. int x,y,z,q;
  71. if(e2==true && e1==true && isi==true && twoItems){
  72. std::stringstream ss(str);
  73. ss>>x>>z>>y>>q;
  74. x=x^z;
  75. y=y^q;
  76. }if(e2==false && e1==true && isi==true && twoItems){
  77. std::stringstream ss(str);
  78. ss>>x>>y>>q;
  79. y=y^q;
  80. }if(e2==false && e1==true && isi==true && twoItems){
  81. std::stringstream ss(str);
  82. ss>>x>>z>>y;
  83. x=x^z;
  84. }if(e2==false && e1==false && isi==true && twoItems){
  85. std::stringstream ss(str);
  86. ss>>x>>y;
  87. }if( eAll==true && isi==true && !twoItems){
  88. std::stringstream ss(str);
  89. ss>>y>>q;
  90. y=y^q;
  91. }if(eAll==false && isi==true && !twoItems){
  92. std::stringstream ss(str);
  93. ss>>y;
  94. }if( eAll==true && isi==false && !twoItems){
  95. std::stringstream ss(str);
  96. ss>>x>>z;
  97. x=x^z;
  98. }if(eAll==false && isi==false && !twoItems){
  99. std::stringstream ss(str);
  100. ss>>x;
  101. }
  102.  
  103.  
  104.  
  105. cout<<x<<" "<<y<<endl;
  106.  
  107.  
  108.  
  109.  
  110.  
  111. return 0;
  112. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:47:41: error: invalid conversion from ‘const char*’ to ‘std::__cxx11::basic_string<char>::size_type {aka long unsigned int}’ [-fpermissive]
  string s1=str.substr(1,str.find("+","-"));
                                         ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/basic_string.h:2053:7: note:   initializing argument 2 of ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::find(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
       find(const _CharT* __s, size_type __pos = 0) const
       ^~~~
prog.cpp:48:39: error: invalid conversion from ‘const char*’ to ‘std::__cxx11::basic_string<char>::size_type {aka long unsigned int}’ [-fpermissive]
  string s2=str.substr(str.find("+","-"), str.length());
                                       ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/basic_string.h:2053:7: note:   initializing argument 2 of ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::find(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
       find(const _CharT* __s, size_type __pos = 0) const
       ^~~~
stdout
Standard output is empty