题目 洛谷P1421 小玉买文具
题目描述
班主任给小玉一个任务,到文具店里买尽量多的签字笔。已知一只签字笔的价格是1元9角,而班主任给小玉的钱是a元b角,小玉想知道,她最多能买多少只签字笔呢。
输入格式
输入的数据,在一行内,包括两个整数,依次表示a和b,a<=10000,b<=9。
输出格式
输出一个整数,表示小玉最多能买多少只签字笔。
输入输出样例
输入 #1
10 3
输出 #1
5
------------------------------------分割-----------------------------------
大型翻车:测试洛谷题库,没想到居然WA了
思路
简单数学计算,读入A,B,n为总钱数,利用int特性,k=n/1.9直接(相当于忽略余数)算
注意:A,B定义为double,避免B/10==0;(否则:b=2,2/10=0,WA)
附上代码
1 #include<iostream> 2 using namespace std; 3 double a,b; 4 double n; 5 int k; 6 int main() 7 { 8 cin>>a>>b; 9 n=a+b/10; 10 k=n/1.9; 11 cout<<k; 12 return 0; 13 }