There is a program that compares lines in a cycle, everything in it works, but in the end the time limit is exceeded by 0.001 - 0.007 seconds. I decided with each iteration to cut off the first character to speed up the cycle, but how to do it ?! PS The length of the string can be up to 100,000 characters.
Code:
#include <fstream> #include <cstring> std::ofstream cout("output.txt"); std::ifstream cin("input.txt"); int main() { char e[100002] , m[100002] , s[100002]; int l ; cin >> e ; cin >> m ; cin >> s ; l = strlen(e); for (int i=0; i <= l ;i++) { if (strncmp(m,e,i) != 0 || strncmp(s,e,i) != 0 ) { if (strncmp(m,e,i) == 0 && strncmp(s,e,i) != 0 ) { cout << "Masha"; break; } if (strncmp(m,e,i) != 0 && strncmp(s,e,i) == 0 ) { cout << "Sasha"; break; } if (strncmp(m,e,i) != 0 && strncmp(s,e,i) != 0 ) { cout << "Draw"; break; } break; } else { continue;} } return 0; }