Problem Description
Given a positive integer
- Even Position: If the current digit is even, add the square of that digit to the energy value;
- High-Risk Odd: If the current digit is odd and greater than 5, add the cube of that digit to the energy value;
- Normal Odd: In other cases, simply add that digit to the energy value.
Input Format
A positive integer n.
Output Format
A positive integer representing the generated energy value
Examples
Input Data 1
508
Output Data 1
069
Input Data 2
99
Output Data 2
1458
Data Range
For 60%% of the data,
For 100%% of the data,
Problem Analysis
This problem is also considered simple, with the main difficulty being how to loop through each digit of n and then determine the energy value based on the extracted digits.
#include<bits/stdc++.h>using namespace std;int main(){ long long n,m,k; cin>>n; m=0; while(n>0) { k=n%10; if(k%2==0) { m+=k*k; } else { if(k>5) { m+=k*k*k; } else { m+=k; } } n=n/10; } if(m<10) { cout<<"00"<<m<<endl; } else if(m<100) { cout<<"0"<<m<<endl; } else { cout<<m<<endl; } return 0;}
