結果
問題 | No.22 括弧の対応 |
ユーザー | yuki2006 |
提出日時 | 2014-11-01 04:18:11 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,162 bytes |
コンパイル時間 | 509 ms |
コンパイル使用メモリ | 66,560 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-08-29 00:05:10 |
合計ジャッジ時間 | 1,527 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:5: warning: ‘targetlevel’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (level == targetlevel) { ^~
ソースコード
/* yukicoder No.22 ä½æè ï¼ããã½ã 使ç¨è¨èªï¼C/C++ */ #include <iostream> #include <iomanip> #include <stack> #include <cstdio> #include <cstring> using namespace std; int main(void) { int N, K; char *lpString; cin >> N >> K; printf("N = %d , K = %d\n", N, K); K--; lpString = new char[N + 1]; cin >> setw(N + 1) >> lpString; printf("strlen() = %d\n", strlen(lpString)); if (*(lpString + K) == '(') { //Kçªç®ã(ã®å ´å int level = 0; int targetlevel; for (int i = 0; i < N; i++) { if (*(lpString + i) == '(') { level++; if (i == K) { targetlevel = level; } } else if (*(lpString + i) == ')') { if (level == targetlevel) { printf("%d\n", i + 1); break; } level--; } } } else { //Kçªç®ã)ã®å ´å stack<int> PosStack; for (int i = 0; i < K ; i++) { if (*(lpString + i) == '(') PosStack.push(i); else if (*(lpString + i) == ')') PosStack.pop(); } printf("%d\n", PosStack.top() + 1); } delete[]lpString; return 0; }