結果

問題 No.49 算数の宿題
ユーザー ohreitetsuohreitetsu
提出日時 2018-06-13 18:13:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 71,208 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 17:39:34
合計ジャッジ時間 1,165 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,504 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main(int, char**)’ 内:
main.cpp:24:28: 警告: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   24 |         GetData(dataList,S,"*+");
      |                            ^~~~

ソースコード

diff #

#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;
}
0