Submission #340050

#TimeUsernameProblemLanguageResultExecution timeMemory
340050AlperenTSlon (COCI15_slon)C++17
0 / 120
13 ms1260 KiB
#include <bits/stdc++.h> using namespace std; long long p, m, numx, numa; string str, postfix; stack<char> poststack; struct operand{ long long x, a; operand operator+(operand y){ struct operand temp; temp.x = x + y.x; temp.a = a + y.a; return temp; } operand operator-(operand y){ struct operand temp; temp.x = x - y.x; temp.a = a - y.a; return temp; } operand operator*(operand y){ struct operand temp; if(x == 0){ temp.x = a * y.x; temp.a = a * y.a; } else{ temp.x = y.a * x; temp.a = y.a * a; } return temp; } }; stack<operand> operands; int main(){ cin >> str >> p >> m; for(int i = 0; i < str.size(); i++){ if(str[i] == 'x'){ postfix += str[i]; postfix += " "; } else if(isdigit(str[i])){ long long val = 0; while(i < str.size() && isdigit(str[i])){ val = (val * 10) + (str[i] - '0'); i++; } postfix += to_string(val); postfix += " "; i--; } else{ if(str[i] == '+' || str[i] == '-'){ while(!poststack.empty() && poststack.top() != '(' && poststack.top() != ')'){ postfix += poststack.top(); postfix += " "; poststack.pop(); } poststack.push(str[i]); } else if(str[i] == '*'){ while(!poststack.empty() && poststack.top() == '*' && poststack.top() != '(' && poststack.top() != ')'){ postfix += poststack.top(); postfix += " "; poststack.pop(); } poststack.push(str[i]); } else if(str[i] == '('){ poststack.push(str[i]); } else if(str[i] == ')'){ while(!poststack.empty() && poststack.top() != '('){ postfix += poststack.top(); postfix += " "; poststack.pop(); } if(poststack.top() == '('){ poststack.pop(); } } } } while(!poststack.empty()){ postfix += poststack.top(); postfix += " "; poststack.pop(); } for(int i = 0; i < postfix.size(); i++){ if(isdigit(postfix[i])){ long long val = 0; while(i < postfix.size() && isdigit(postfix[i])){ val = (val * 10) + (postfix[i] - '0'); i++; } struct operand temp; temp.x = 0; temp.a = val; operands.push(temp); } else if(postfix[i] == 'x'){ struct operand temp; temp.x = 1; temp.a = 0; operands.push(temp); } else if(postfix[i] == '+' || postfix[i] == '-' || postfix[i] == '*'){ struct operand tempa, tempb; tempb = operands.top(); operands.pop(); tempa = operands.top(); operands.pop(); if(postfix[i] == '+'){ operands.push(tempa + tempb); } else if(postfix[i] == '-'){ operands.push(tempa - tempb); } else{ operands.push(tempa * tempb); } } } numx = operands.top().x; numa = operands.top().a; for(long long i = 0; i <= m; i++){ if((numx * i + numa) % m == p){ cout << i; return 0; } } }

Compilation message (stderr)

slon.cpp: In function 'int main()':
slon.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0; i < str.size(); i++){
      |                 ~~^~~~~~~~~~~~
slon.cpp:55:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    while(i < str.size() && isdigit(str[i])){
      |          ~~^~~~~~~~~~~~
slon.cpp:102:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  for(int i = 0; i < postfix.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
slon.cpp:106:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |    while(i < postfix.size() && isdigit(postfix[i])){
      |          ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...