結果
| 問題 |
No.2768 Password Crack
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-06-01 12:39:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 813 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 40,832 KB |
| 最終ジャッジ日時 | 2025-02-21 19:00:57 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int query(char*)’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &r);
| ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:35:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2768.cc: No.2768 Password Crack - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 100;
/* typedef */
/* global variables */
char s[MAX_N + 4];
/* subroutines */
int query(char s[]) {
printf("? %s\n", s); fflush(stdout);
int r;
scanf("%d", &r);
return r;
}
/* main */
int main() {
int n;
scanf("%d", &n);
fill(s, s + n, 'a');
int an = query(s);
if (an < n) {
for (int i = 0; i < n; i++) {
char c = 'b';
for (; c < 'z'; c++) {
s[i] = c;
int r = query(s);
if (r < i + an) { c = 'a'; break; }
if (r > i + an) break;
}
s[i] = c;
if (c == 'a') an--;
}
}
printf("! %s\n", s); fflush(stdout);
//for (int i = 0; i < 1000000000; i++);
return 0;
}
tnakao0123