結果

問題 No.167 N^M mod 10
ユーザー TLwiegehtt
提出日時 2015-07-12 22:33:28
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,198 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 21,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 01:17:23
合計ジャッジ時間 1,347 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:59:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |         scanf("%s", n);
      |         ^~~~~~~~~~~~~~
main.c:60:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         scanf("%s", m);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <stdio.h>
int sub(char *s){
int i, len;
int mod = 0;
int minus = 0;
for(len=0;s[len] != '\0';len++);
for(i=len-1;i>0 ;i--){
if(minus == 1){
if(s[i] == '0'){
s[i] = '9';
minus = 1;
}else{
char num = (char)(s[i] - '0' - 1);
s[i] = (char)(num+'0');
minus = 0;
}
}else{
if( s[i] == '0'){
s[i] = '9';
minus = 1;
}else{
char num = (char)(s[i] - '0' - 1);
s[i] = (char)(num+'0');
}
}
if(minus == 0){break;}
}
for(i=0;i<len;i++){
mod = mod*10 + (int)(s[i]-'0');
mod = mod%4;
}
return mod+1;
}
int main(void){
int ans[10][5] = {
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 1},
{0, 2, 4, 8, 6},
{0, 3, 9, 7, 1},
{0, 4, 6, 4, 6},
{0, 5, 5, 5, 5},
{0, 6, 6, 6, 6},
{0, 7, 9, 3, 1},
{0, 8, 4, 2, 6},
{0, 9, 1, 9, 1}
};
int num;
int lenN, lenM;
int mul;
char n[10010];
char m[10010];
scanf("%s", n);
scanf("%s", m);
for(lenN=0;n[lenN] != '\0';lenN++);
for(lenM=0;m[lenM] != '\0';lenM++);
num = (int)(n[lenN-1]-'0');
if( lenM == 1 ){
mul = (int)((m[0]-'0'-1)%4+1);
if(m[0] == '0'){
num = 1;
mul = 1;
}
}else{
mul = sub(m);
}
printf("%d\n", ans[num][mul]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0