Just a Numble

Description
Now give you two integers n m, you just tell me the m-th number after radix point in 1/n,for example n=4,the first numble after point is 2,the second is 5,and all 0 followed

Input
Each line of input will contain a pair of integers for n and m(1<=n<=10^7,1<=m<=10^5)

Output
For each line of input, your program should print a numble on a line,according to the above rules

Sample Input
4 2
5 7
123 123

Sample Output
5
0

8

我只想说平时不切题,赛时徒伤悲!!!
可以说这是一个公式,注意n=1的情况。
#include<stdio.h>
int main()
{
    int n,m,i;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int ans,a=10,k;
        if(n==1)
        printf("0\n");
        for(i=0;i<m;i++)
        {
            ans=a/n;
            k=a%n;
            a=k*10;
        }
        printf("%d\n",ans);
    }
    return 0;
}


continue to use Java language, Add a class Borrower that extends User. The constructor of the Borrower class takes a name and a number of books borrowed by the borrower. If the number of books given as argument is strictly less than zero, then the constructor must throw a NotALenderException with the message “A new borrower cannot lend books.”. The borrower class does not have any instance variable. The moreBook method of the Borrower class increases the number of books borrowed by the borrower by the number of books given as argument to the method (so the books borrowed by the borrower becomes more positive!) For example, if a borrower currently borrows 10 books and moreBook(2) is called then the borrower borrows 12 books. It is fine for the moreBook method to be given a negative value as argument, which means the borrower then just returned some books. For example, if a borrower currently borrows 10 books and moreBook(-2) is called then the borrower borrows 8 books. However, a borrower cannot lend books, so the number of books borrowed by the borrower must always be positive or zero, never negative. If the argument given to the moreBook method is too negative and would change the book variable into a negative value, then the number of books borrowed by the borrower must not change and the moreBook method must throw a NotALenderException with the message “A borrower cannot lend XXX book(s).”, where XXX is replaced with the result of -(book + number). For example, if a borrower currently borrows 10 books and moreBook(-12) is called then the borrower still borrows 10 books and the method throws a NotALenderException with the message “A borrower cannot lend 2 book(s).”. Note: to simplify the project, do not worry about the setBook method. Change other classes and interfaces as necessary
最新发布
05-25
Here is the updated code with the Borrower class: ```java public class NotALenderException extends Exception { public NotALenderException(String message) { super(message); } } public class User { private String name; public User(String name) { this.name = name; } public String getName() { return name; } } public class Borrower extends User { private int booksBorrowed; public Borrower(String name, int booksBorrowed) throws NotALenderException { super(name); if (booksBorrowed < 0) { throw new NotALenderException("A new borrower cannot lend books."); } this.booksBorrowed = booksBorrowed; } public void moreBook(int number) throws NotALenderException { int newBooksBorrowed = booksBorrowed + number; if (newBooksBorrowed < 0) { throw new NotALenderException("A borrower cannot lend " + (-newBooksBorrowed) + " book(s)."); } booksBorrowed = newBooksBorrowed; } public int getBooksBorrowed() { return booksBorrowed; } } ``` In this updated code, the Borrower class extends the User class and has an additional instance variable `booksBorrowed` which represents the number of books borrowed by the borrower. The constructor of the Borrower class takes a name and a number of books borrowed by the borrower. If the number of books given as argument is strictly less than zero, then a NotALenderException is thrown. The moreBook method of the Borrower class increases or decreases the number of books borrowed by the borrower by the number of books given as argument to the method. If the argument given to the moreBook method is too negative and would change the book variable into a negative value, then a NotALenderException is thrown. The getBooksBorrowed method returns the number of books borrowed by the borrower.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值