結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー pengin_2000
提出日時 2025-10-24 21:28:18
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 26,704 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-24 21:28:21
合計ジャッジ時間 1,152 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘solve’:
main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%s", s);
      |         ^~~~~~~~~~~~~~
main.c: In function ‘main’:
main.c:35:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
char s[500005];
void solve()
{
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	int i;
	int ans = 0, sig = 1;
	for (i = 0; i < n; i++)
	{
		if ('0' <= s[i] && s[i] <= '9')
		{
			if (sig > 0)
				ans += '9' - s[i];
			else
				ans += s[i] - '1';
		}
		else
		{
			if (sig > 0)
				ans += 9;
			if (s[i] == '+')
				sig = 1;
			else if (s[i] == '-')
				sig = -1;
		}
	}
	printf("%d\n", ans);
	return;
}
int main()
{
	int t;
	scanf("%d", &t);
	for (; t > 0; t--)
		solve();
	return 0;
}
0