首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【Codeforces】659A - Round House

【Codeforces】659A - Round House

作者头像
FishWang
发布2025-08-26 20:12:45
发布2025-08-26 20:12:45
8900
代码可运行
举报
运行总次数:0
代码可运行

A. Round House  time limit per test1 second  memory limit per test256 megabytes  inputstandard input  outputstandard output  Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.

Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.

Illustration for n = 6, a = 2, b =  - 5.  Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

Input  The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya’s place, the number of his entrance and the length of his walk, respectively.

Output  Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

Examples  input  6 2 -5  output  3  input  5 1 3  output  4  input  3 2 7  output  3  Note  The first example is illustrated by the picture in the statements.

读题真是费了点功夫,读懂了就不难了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
int main()
{
	int n,a,b;
	int re;
	while (~scanf ("%d %d %d",&n,&a,&b))
	{
		if (b > 0)
		{
			re = b % n;
			a += re;
			if (a > n)
				printf ("%d\n",a-n);
			else
				printf ("%d\n",a);
		}
		else
		{
			int t = -b;
			re = t % n;
			a -= re;
			if (a <= 0)
				printf ("%d\n",a+n);
			else
				printf ("%d\n",a);
		}
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-04-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档