結果

問題 No.170 スワップ文字列(Easy)
コンテスト
ユーザー takatowin
提出日時 2017-01-17 00:37:10
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 611 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 219 ms
コンパイル使用メモリ 39,328 KB
最終ジャッジ日時 2026-02-24 00:06:37
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:24:3: warning: 'gets' is deprecated [-Wdeprecated-declarations]
   24 |   gets(s);
      |   ^~~~
In file included from main.c:1:
/usr/include/stdio.h:667:14: note: declared here
  667 | extern char *gets (char *__s) __wur __attribute_deprecated__;
      |              ^~~~
/usr/bin/ld: /tmp/ccKLYbzg.o: in function `main':
main.c:(.text.startup+0xb): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #
raw source code

#include<stdio.h>
#include<string.h>
void sort(char *p){
  int i,j;
  char temp;
  for(i=strlen(p);i>0;i--){
    for(j=0;j<i-1;j++){
      if(p[j]>p[j+1]){
        temp=p[j];
        p[j]=p[j+1];
        p[j+1]=temp;
      }
    }
  }
}
int f(int a){
  if(a==1 || a==0)
    return 1;
  else return a*f(a-1);
}
int main(void){
  int i=0,j=0,k=1,t[9],temp=-1;
  char s[9];
  gets(s);
  sort(s);
  for(i=0;i<9;i++)
    t[i]=1;
  for(i=0;i<strlen(s)-1;i++){
    if(s[i]==s[i+1])
      t[j]++;
    else
      j++;
  }

  for(i=0;i<9;i++)
    k*=f(t[i]);
  temp+=f(strlen(s))/k;
  printf("%d\n",temp);
  return 0;
}

0