Submission #1003425

#TimeUsernameProblemLanguageResultExecution timeMemory
1003425LiniKemija (COCI22_kemija)C++14
50 / 50
1 ms348 KiB
#include <iostream> #include <vector> #include <cctype> using namespace std; vector<vector<pair<char,long>>> eq; int main() { long n; string chem; cin>>n; eq.resize(n); long sec=1; long molno=1; long elno=1; bool found; for (long i=0; i<n; i++){ sec=1; molno=1; elno=1; found=false; cin>>chem; for (long k=0; k<chem.length(); ++k){ char el=chem[k]; if(isdigit(el)){ molno=el-'0'; continue; } if (el=='-'){ sec=-1; continue; } if (el=='+' or el=='>'){ molno=1; if (isdigit(chem[k+1])){ molno = chem[k+1]-'0'; ++k; continue; } } elno=1; found=false; if (eq[i].size()!=0){ for (long j=0; j<eq[i].size(); j++){ if (eq[i][j].first == el){ if (isdigit(chem[k+1])){ elno=chem[k+1]-'0'; ++k; } // cout<<el<<k<<": "<<elno<<"*"<<molno<<"*"<<sec<<endl; eq[i][j].second += elno*molno*sec; found=true; } } if (found) {continue;} } if (el!='-' and el!='>' and el!='+' and not isdigit(el)){ pair <char, long> p; p.first=el; if (isdigit(chem[k+1])){ elno=chem[k+1]-'0'; ++k; } // cout<<el<<k<<": "<<elno<<"*"<<molno<<"*"<<sec<<endl; p.second=elno*molno*sec; eq[i].push_back(p); } } //cout<<eq[i].size()<<endl; for (long x=0; x<eq[i].size(); ++x){ pair<char, long> elem=eq[i][x]; // cout<<elem.first<<", "<<elem.second<<endl; } } bool balanced; for (long l=0; l<n; ++l){ balanced=true; for (pair<char, long> e : eq[l]){ if (e.second!=0){ balanced=false; break; } } if (balanced){cout<<"DA"<<endl;} else{cout<<"NE"<<endl;} } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:24:25: warning: comparison of integer expressions of different signedness: 'long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (long k=0; k<chem.length(); ++k){
      |                        ~^~~~~~~~~~~~~~
Main.cpp:45:33: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<char, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 for (long j=0; j<eq[i].size(); j++){
      |                                ~^~~~~~~~~~~~~
Main.cpp:72:25: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<char, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (long x=0; x<eq[i].size(); ++x){
      |                        ~^~~~~~~~~~~~~
Main.cpp:73:30: warning: variable 'elem' set but not used [-Wunused-but-set-variable]
   73 |             pair<char, long> elem=eq[i][x];
      |                              ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...