NC54750. Buying Keys
描述
输入描述
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"); }