还是字符串适合我

发布时间:2018-01-23 12:06:15
贴主:夏季聆听知了的鸣声哟
热度:1
正在讨论:P1564 - 没有0的数字 题目传送门

夏季聆听知了的鸣声哟 2018-01-23

#include<iostream>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
unsigned long long factorial(int a)
{
 unsigned long long factorial0 = 1;
 for (int i = 2; i <= a; i++)factorial0 *= i;
 return factorial0;
}
int main()
{
 int n; scanf("%d", &n);
 for (int j = 0; j < n; j++)
 {
  int a, temp; scanf("%d", &a);
  unsigned long long all = factorial(a);
  char s[20]; sprintf(s, "%lld", all); temp = strlen(s);
  for (int i = strlen(s) - 1; i >= 0; i--)
  if (s[i] == '0')temp = i;
  for (int i = temp; s[i] != 0; i++)s[i] = '0';
  if (temp != strlen(s))all = stoull(s) - 1;
  cout << all << endl;
 }
 return 0;
}

(0)

Copyright 2016 - 2024 XUJC ACM Team
闽ICP备2020022076号-1