結果
問題 | No.49 算数の宿題 |
ユーザー |
|
提出日時 | 2018-06-13 18:13:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 905 bytes |
コンパイル時間 | 937 ms |
コンパイル使用メモリ | 72,812 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:59:23 |
合計ジャッジ時間 | 1,226 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function 'int main(int, char**)': main.cpp:24:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 24 | GetData(dataList,S,"*+"); | ^~~~
ソースコード
#include <iostream>#include <string>#include <string.h>#include <vector>using namespace std;int GetData(vector<string> &dataList,char *line,char *deli){//注意:lineは壊れるchar Line[4096];strcpy(Line,line);char* token = strtok(Line, deli);while (token != NULL) {dataList.push_back(token);token = strtok(NULL, deli);}return 0;}int main(int argc, char* argv[]){char S[4096];fgets(S,4096,stdin);vector<string> dataList;GetData(dataList,S,"*+");char OP[4096];int opNum=0;int i,j=0;int strLen=strlen(S);for (i=0;i<strLen;i++){if (S[i]=='*' || S[i]=='+'){OP[j++]=S[i];}}opNum=j;j=0;int data=atol(dataList[0].c_str());for (i=1;i<dataList.size();i++){int data1=atol(dataList[i].c_str());switch(OP[j++]){case '*':data=data+data1;break;case '+':data=data*data1;break;}}cout<<data<<endl;return 0;}