Files

32 lines
1013 B
Java
Raw Permalink Normal View History

2017-03-10 01:10:37 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-03-10 01:10:37 -06:00
import java.util.Scanner;
2017-04-05 18:42:35 -05:00
/*
We start off at some random prisoner S and try to distribute M candies. We could just do
S + M to see which prisoner we end up at. However, we may have more candies than prisoners,
so we loop back around to the first prisoner by doing the % N where N is number of prisoners.
Each +1 and -1 that you see in the equation is to fix the off-by-one problems that exist
since prisoners are counted from 1 to N while modular arithmetic is counted from 0.
*/
2017-03-10 01:10:37 -06:00
public class Solution {
2017-09-11 09:32:17 -07:00
public static void main(String[] args) {
2017-03-10 01:10:37 -06:00
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while (T-- > 0) {
int N = scan.nextInt();
int M = scan.nextInt();
int S = scan.nextInt();
int last = ((S - 1) + (M - 1)) % N + 1;
System.out.println(last);
}
scan.close();
}
}