Skip to content

Instantly share code, notes, and snippets.

@satellitex
Created July 13, 2014 10:20
Show Gist options
  • Select an option

  • Save satellitex/558d2b359b82a4bb3192 to your computer and use it in GitHub Desktop.

Select an option

Save satellitex/558d2b359b82a4bb3192 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int N;
char buf[65536];
string find_answer(string s){
string search = "<label for=\"";
int id;
if( ( id = s.find(search) ) == string::npos) return "";
string sub = s.substr( s.find(search) + search.size() );
int i = 0;
while( sub[i] != '>' ){
++i;
}
i+=4;
string sub2 = sub.substr(i);
return sub2.substr( 0, sub2.find("</label>") );
}
int main(){
while( fgets(buf,sizeof(buf),stdin) != '\0'){
string S = buf;
string search1 = "<div class=\"qtext\">";
int id;
if( (id = S.find( search1 )) != string::npos ) {
string sub = S.substr( id + search1.size() );
string q = sub.substr(0, sub.find("</div>"));
cout << "question::" << endl;
cout << q << endl;
int correct=-1;
int wrong = -1;
string ans[3];
ans[0] = find_answer(S);
if( S.find( "Correct!" ) != string::npos) correct = 0;
if( S.find( "Wrong!" ) != string::npos) wrong = 0;
for(int i=1;i<3;i++) {
fgets(buf,sizeof(buf),stdin);
S = buf;
ans[i] = find_answer(S);
if( S.find( "Correct!" ) != string::npos) correct = i;
if( S.find( "Wrong!" ) != string::npos) wrong = i;
}
if( correct == -1 ){
cout << "answer 2" << endl;
for(int i=0;i<3;i++){
if( i == wrong ) continue;
cout << ans[i] << endl;
}
} else {
cout << "answer 1" << endl;
cout << ans[correct] << endl;
}
cout << endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment