列表

详情


NC54750. Buying Keys

描述

One day Xiao Ming is not happy because he has no idea about how to run out of his pocket money. At that moment, a mysterious man appears with a smile:"My keys are on sale, three yuan can buy a key, ten yuan can buy three keys.How many keys do you wanna buy?" 
Xiaoming is attracted by mysterious man and wants to spend all his money on buying keys. He doesn't want keep any money at the end. At the same time, because of the heavy weight of keys, Xiaoming Hopes that he can buy as few keys as possible. At the beginning, Xiao Ming had n yuan. Can you tell Xiaoming the minimum number of keys he can bought if he runs out of his pocket money?If Xiaoming can't run out of his money, please output "orz".

输入描述

The first line contains one integer n(1 ≤n ≤1e9), the pocket money Xiaoming have.

输出描述

If Xiaoming can't run out of his money, please output "orz", otherwise output the minimum number of keys he can bought if he runs out of his money.

示例1

输入:

3

输出:

1

示例2

输入:

11

输出:

orz

说明:

It's impossible to run out of his money.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C 解法, 执行用时: 1ms, 内存消耗: 364K, 提交时间: 2022-07-27 20:11:53

#include <stdio.h>
int main()
{
	int n,s,i;
	while(~scanf("%d",&n)){
		s=0;
		for(i=n/10;i>=0;i--){
			if((n-i*10)%3==0){
				s=1;
				break;
			}
		}
		if(s==1) printf("%d\n",i*3+(n-i*10)/3);
		else printf("orz\n");
	}
	return 0;
}

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-01-11 15:48:21

#include<stdio.h>
using namespace std;
int main()
{
	int t=0,i,j,n;
	scanf("%d",&n);
	for(i=0;n>=i*3;i++){
		if((n-i*3)%10==0){
			printf("%d",(n-i*3)/10*3+i);
			return 0;
		}
	}
	printf("orz");
	return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 504K, 提交时间: 2020-01-12 21:08:21

#include<stdio.h>
int main()
{int n,i,s=0;
scanf("%d",&n);
for(i=n/10;i>=0;i--)
{if((n-i*10)%3==0)
 {s=i*3+(n-i*10)/3;
 printf("%d",s);
 break;
 }}
 if(s==0)printf("orz");


}

上一题