题意及思路

题意:略。
思路:我一开始是想将n的每一位都存入一个数组,然后进行进位操作,因为这题比较简单,这样写不困难。但是我阅读其他同学的代码时,才幡然醒悟,这里有一种巧妙的方法。直接上代码(见代码2)。

代码1

#include <iostream>

using namespace std;

const int MAX = 15;
int q[MAX] = {0};

int main(){
    int n;
    cin >> n;
    int t = n,cur = 0,mod = 0;
    while(t!=0){
        mod = t%10;
        t /= 10;
        q[cur++] = mod;
    }
    int carry = 0;
    if(q[0]>=5) {
        carry = 1;
        for(int i=1;i<cur;i++){
            int t = q[i]+carry;
            q[i] = t%10;
            carry = t/10;
        }
        if(carry!=0){
            q[cur++] = carry;
        }
    }
    q[0] = 0;
    for(int i=cur-1;i>=0;i--){
        cout << q[i];
    }
    cout << endl;
    return 0;
}

代码2

#include <iostream> 
using namespace std;

int n;
int main() {
    cin>>n;
    int a = n/10,b = n%10;
    if(b<=4) b = 0;
    else b=10;
    cout << a*10+b << endl;
    return 0;
}