結果

問題 No.435 占い(Extra)
コンテスト
ユーザー testestest
提出日時 2016-10-15 04:25:01
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 389 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 32,540 KB
最終ジャッジ日時 2026-02-23 22:34:23
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:1: warning: data definition has no type or storage class
    2 | n,i,t,ans,c,c3;
      | ^
main.c:3:1: warning: data definition has no type or storage class
    3 | inv9[]={0,1,5,0,7,2,0,4,8};
      | ^~~~
main.c: In function ‘main’:
main.c:8:19: warning: incompatible implicit declaration of built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
    8 |                 n=strlen(s)-1;
      |                   ^~~~~~
main.c:1:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
  +++ |+#include <string.h>
    1 | char s[100010];
main.c:16:17: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   16 |                 printf("%d\n",ans%9?:t?9:0);
      |                 ^~~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
  +++ |+#include <stdio.h>
    1 | char s[100010];
/usr/bin/ld: /tmp/ccFk7Dbq.o: in function `main':
main.c:(.text.startup+0x21): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #
raw source code

char s[100010];
n,i,t,ans,c,c3;
inv9[]={0,1,5,0,7,2,0,4,8};
f3(n){int i=0;for(;n&&n%3==0;n/=3)i++;return i;}
g3(n){for(;n&&n%3==0;n/=3);return n;}
main(){
	for(gets(s);gets(s);){
		n=strlen(s)-1;
		t=ans=c3=0,c=1;
		for(i=0;i<=n;i++){
			t+=s[i]-48;
			ans+=c*(c3?c3==1?3:0:1)*(s[i]-48)%9;
			c3+=f3(n-i)-f3(i+1);
			c=(c*g3(n-i)*inv9[g3(i+1)%9])%9;
		}
		printf("%d\n",ans%9?:t?9:0);
	}
}
0