結果
問題 |
No.2707 Bag of Words Encryption
|
ユーザー |
|
提出日時 | 2024-07-10 17:26:55 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 967 bytes |
コンパイル時間 | 1,560 ms |
コンパイル使用メモリ | 29,312 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-10 17:26:58 |
合計ジャッジ時間 | 2,940 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | WA * 15 |
ソースコード
#include <stdio.h> #include <stdlib.h> #include <string.h> int cnt(char s[], char x) { int cnt = 0; for (int i = 0; s[i] != '\0'; i++) { if (s[i] == x) { cnt++; } } return cnt; } int main(void) { int N; scanf("%d", &N); char S[N + 1]; scanf("%s", S); char A[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 出現回数を格納するためのバッファ char c[4 * 26 + 1] = {0}; // 各文字の出現回数を最大3桁と仮定してバッファを確保 for (int i = 0; i < 26; i++) { int k = cnt(S, A[i]); char buffer[4]; // 一時的なバッファ snprintf(buffer, sizeof(buffer), "%d", k); // 数値を文字列に変換 strcat(c, buffer); // 変換した文字列を結果のバッファに追加 if (i < 25) { strcat(c, " "); // 各出現回数の間にスペースを追加 } } printf("%s\n", c); return 0; }