The problem * the supermarket is now getting a computer next to the reception to encourage the customers visiting there, there once is a natural numbers n
that are 2-digit or 3-digit, 4-digit with no meaningless zeroes.... rule is those customers must enter a number that is at the least, 4-digit and two last digits must equal to sum of two first before number's digits, i.e., computer show out 1311
customers enter 2949
in it. The fastest customer will get a super voucher for a year here.."
My code is:
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n;
cin>>n;
int x=n;
int num=log10(n)+1;
int arr[n]={0};
while (n) {
arr[num--]=n%10;
n/=10;
}
if (x>999) {
}
else if (99<x<=999) {
arr[4]=arr[3];
arr[3]=arr[2];
arr[2]=arr[1];
arr[1]=0;
}
else {
arr[4]=arr[2];
arr[3]=arr[1];
arr[1]=0;
arr[2]=0;
}
if (arr[3]>1)
cout<<"00";
else if (arr[3]==1) {
if (arr[4]==9)
cout<<"00";
else
cout<<arr[3]*10+arr[4]-9<<9;
}
else
cout<<1<<arr[3]*10+arr[4]-1;
if (arr[1]>1)
cout<<"00";
else if (arr[1]==1) {
if (arr[2]==9)
cout<<"00";
else
cout<<arr[1]*10+arr[2]-9<<9;
}
else
cout<<"0"<<arr[1]*10+arr[2];
}
It's wrong for 1234
, output is 0039
, but why is that ?? I need to the helps.
Aucun commentaire:
Enregistrer un commentaire