fork download
  1. #include <string>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5. using namespace std;
  6. class ConundrumReloaded{
  7. public:
  8. int minimumLiars(string answers){
  9. vector<string> v;
  10. string s;
  11. int f=0;
  12. int INF=(1<<28);
  13. for( int i=0; i<answers.size(); i++ ){
  14. if( answers[i] == '?' ){
  15. f = 1;
  16. if( s.size() > 0 ){
  17. v.push_back( s ); s = "";
  18. }
  19. } else {
  20. s += answers[i];
  21. }
  22. }
  23. if( s.size() > 0 ){
  24. if( answers[0] == '?' ) v.push_back( s );
  25. else if( v.size() == 0 ) v.push_back( s );
  26. else v[0] = s + v[0];
  27. }
  28. int ret = 0;
  29. for( auto it=v.begin(); it!=v.end(); ++ it ){
  30. s = *it;
  31. cout << s << endl;
  32. int d0=0,d1=1;
  33. char c0='H',c1='L';
  34. for( int i=0; i<s.size(); i++ ){
  35. c0 = (c0==s[i]) ? 'H' : 'L';
  36. c1 = (c1==s[i]) ? 'H' : 'L';
  37. if( c0 == 'L' ) d0++;
  38. if( c1 == 'L' ) d1++;
  39. cout << c0 << c1 << ' ';
  40. }
  41. if( !f && c0!='H' ) d0 = INF;
  42. if( !f && c1!='L' ) d1 = INF;
  43. if( !f && d1 != INF && c1=='L' ) d1--;
  44. if( d0 == INF && d1 == INF ) ret = -1;
  45. else ret += min( d0, d1 );
  46. }
  47. return ret;
  48. }
  49. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int ConundrumReloaded::minimumLiars(std::string)’:
prog.cpp:13:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0; i<answers.size(); i++ ){
                                  ^
prog.cpp:34:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for( int i=0; i<s.size(); i++ ){
                              ^
/usr/lib/gcc/i486-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty