AcWing.5149.简单计算

发布时间 2023-09-21 02:43:43作者: neKo333

AcWing.5149.简单计算

给定三个整数 \(x,y,z\),请你计算并输出 \(⌊(z-y)/x⌋*x+y\) 的值。注意,⌊ ⌋ 表示向下取整。

输入格式

第一行包含整数 T,表示共有 T组测试数据。
每组数据占一行,包含三个整数 \(x,y,z\)

输出格式

每组数据输出一行结果。

数据范围

前 33 个测试点满足 \(1≤T≤10\)
所有测试点满足 \(1≤T≤50000\)\(2≤x≤10^9\)\(0≤y<x\)\(y≤z≤10^9\)

输入样例:

3
7 5 12345
5 0 4
10 5 15

输出样例:

12339
0
15
思路分析:向下取整可以使用floor()函数,向上取整可以使用ceil()函数,在c++中,整数相除默认使用向下取整。
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int fc(int x,int y,int z){
    return floor((z-y)/x)*x+y;
}
int t,x,y,z;
int main(){
    cin>>t;
    while(t--){
        cin>>x>>y>>z;
        cout<<fc(x,y,z)<<endl;
    }
    return 0;
}