結果

問題 No.25 有限小数
ユーザー itezpaceitezpace
提出日時 2016-08-31 10:06:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 790 bytes
コンパイル時間 908 ms
コンパイル使用メモリ 64,860 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 21:29:42
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;

string to_string2(double val){
  char buff[numeric_limits<double>::max_exponent10+15+3];
  sprintf(buff,"%.15f",val);
  return buff;
}

int main(){
  ll n,m;
  cin>>n;
  cin>>m;

  int y=-1;
  if(n%m==0){
    int x=n/m;
    string s=to_string(x);
    for(ll i=s.size()-1; i>=0; --i){
      char a=s[i];
      if(a!='0'){
        y=a-'0';
        break;
      }
    }
  } else {
    double x=n;
    x/=m;
    string s=to_string2(x);
    for(ll i=s.size()-1; i>0; --i){
      char a=s[i];
      if(a=='0'){
        char b=s[i-1];
        if(b!='0' && b!='.'){
          y=b-'0';
          break;
        }
      }
    }
  }
  cout<<y<<endl;
  return 0;
}
0