Official

B - Round Down Editorial by QCFium


以下のように処理すればよいです。

  • \(X\) を文字列として受け取る
  • \(X\) に小数点が入っているならば、小数点の手前までを出力する
  • \(X\) に小数点が入っていないならば、\(X\) をそのまま出力する

解答例 (C)

#include <stdio.h>
#include <string.h>

int main() {
	char x[203];
	scanf("%s", x);
	char *dot_pos = strchr(x, '.');
	if (dot_pos) *dot_pos = '\0';
	puts(x);
	return 0;
}

解答例 (Python)

x = input()
dot_pos = x.find('.')
if dot_pos != -1 : x = x[:dot_pos]

print(x)

posted:
last update: