結果

問題 No.49 算数の宿題
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-20 20:25:33
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,095 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 53,412 KB
最終ジャッジ日時 2024-04-27 04:56:13
合計ジャッジ時間 1,261 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:75: error: ‘pow’ was not declared in this scope; did you mean ‘now’?
   20 |                                                 now += (s[i] - '0')     * pow(10, cnt);
      |                                                                           ^~~
      |                                                                           now
main.cpp:25:75: error: ‘pow’ was not declared in this scope; did you mean ‘now’?
   25 |                                                 now += (s[i] - '0')     * pow(10, cnt + 1);
      |                                                                           ^~~
      |                                                                           now
main.cpp:37:75: error: ‘pow’ was not declared in this scope; did you mean ‘now’?
   37 |                                                 now += (s[i] - '0')     * pow(10, cnt);
      |                                                                           ^~~
      |                                                                           now
main.cpp:42:75: error: ‘pow’ was not declared in this scope; did you mean ‘now’?
   42 |                                                 now += (s[i] - '0')     * pow(10, cnt + 1);
      |                                                                           ^~~
      |                                                                           now

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

int main(void){
	string s; cin >> s;
	long long ans = 0;
	int memo = 0;//0 = (*) 1 = (+)
	for (int l = 0; l < s.size(); ++l){
		double cnt = -1;
		int now = 0;
		int r;

		for (r = l; r < s.size(); ++r){
			if(s[r] == '*' || r == s.size() - 1){
				if(r != s.size() - 1){
					for (int i = l; i < r; ++i){
						now += (s[i] - '0')	* pow(10, cnt);
						cnt--;
					}
				}else{
					for (int i = l; i <= r; ++i){
						now += (s[i] - '0')	* pow(10, cnt + 1);
						cnt--;
					}
				}
				if(memo == 0) ans += now;
				else ans *= now;
				memo = 0;
				break;

			}else if(s[r] == '+' || r == s.size() - 1){
				if(r != s.size() - 1){
					for (int i = l; i < r; ++i){
						now += (s[i] - '0')	* pow(10, cnt);
						cnt--;
					}
				}else{
					for (int i = l; i <= r; ++i){
						now += (s[i] - '0')	* pow(10, cnt + 1);
						cnt--;
					}
				}
				if(memo == 0) ans += now;
				else ans *= now;
				memo = 1;
				break;
			}
			cnt++;	
		}
		l = r;
	}
	printf("%lld\n", ans);
	return 0;
}
0