写代码首先要逻辑清晰,这道题是先看她能否剩下钱,如果能,再把整100的存给麻麻,零钱给自己。循环每一轮都先判断她能否剩下钱
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int i, arr[12], result = 0;
int sum2 = 0;
for ( i = 0; i < 12; i++)
scanf("%d", &arr[i]);
for ( i = 0; i < 12; i++){
result = result + 300 - arr[i];
if (result < 0){
printf("-%d", i + 1);
return 0;
}
else{
sum2 += result/100;
result %= 100;
}
}
printf("%d", sum2*120 + result);
return 0;
}