牛客寒假基础集训营 | Day1 D题—hanayo和米饭

在这里插入图片描述

一. 题目描述

hanayo很喜欢吃米饭。
有一天,她拿出了 个碗,第一个碗装了 1 粒米饭,第二个碗装了 2 粒米饭,以此类推,第 n 个碗装了 n 粒米饭。
然而,爱搞恶作剧的rin把所有的碗的顺序打乱,并拿走了一个碗。hanayo想知道,rin拿走的碗里有多少粒米饭?

二. 测试用例

三. 代码

#include <iostream>
using namespace std;
#include <cmath>
int main(){
    int n;
    cin >> n;
    int rice_mass = ((n+1)*n)/2;
    int now_rice_mass = 0;
    for(int i=0;i<n-1;i++){
        int foo;
        cin >> foo;
        now_rice_mass += foo;
    }    
    cout << (rice_mass - now_rice_mass) << endl;
    return 0;
}
发布了137 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_34170700/article/details/104171730