Original
Addition variable multiplication
We all know: 1+2+3+ ... + 49 = 1225
You are now asked to turn two of these nonadjacent plus signs into multiplication sign, making the result 2015
Like what:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
Is the answer that meets the requirements.
Please look for another possible answer and submit the number to the left of the front multiplication sign (for example, commit 10).
Note: You are required to submit an integer, do not fill in any superfluous content.
This idea is very simple, there are 48 ' + ', the topic requires that two of the non-adjacent ' + ' sign into the ' * ' number after the result is 2015.
Start with the 1th ' + ', then turn the 1th to 46th ' + ' to the ' * ', position the first ' + ' and position the second ' + ',
That is, the second ' + ' is positioned after the first ' + ' (note that the first ' + ' cannot be 10). Position the two ' + ' numbers after the judgment.
The child value equals 2015, which is equal to jumping out of the loop, otherwise continuing the loop.
#include <stdio.h>intMain () {inti; ints1=0; intS2=0; intTotal=0; intJ; for(i=1; i<= $; i++)//i,j value cannot be changed { if(i==Ten) Continue; S1=i* (i+1);//First * Value for(j=i+2; j<= -; j + +) {s2=j* (j+1);//a second * value intVari; for(vari=1; vari<= the; vari++) { if(Vari!=i && vari!=i+1&& vari!=j && vari!=j+1) Total=total+Vari; } Total=total+s1+S2; if(total== -) {printf ("%d", i); return 0; } Else{ Total=0; Continue; }}} printf ("%d", i); return 0;}
The following code is the same way of thinking, is to review their own back knocking.
#include <stdio.h>intflag=0;intHfS0;intMain () {intI=0; intj=0;//J represents the number in front of the first * intz=0;//Z represents the number in front of the second * intTotal=0; for(j=1; j<= $; j + +) {//Locate the first one * if(j==Ten){ Continue; } for(i=1; i<= the; i++){ if(I==J) {//Locate the first one *total+=i* (i+1); inti_t=0; while(i_t!=i+2) {i_t++; } intTotal_=total;//the total value of the first phase of backup inti_tt=i_t;//back value for backup first stage for(z=j+2; z<= -; z++) {//position the second one. for(i_t=i_tt;i_t<= the; i_t++){ if(i_t==z) { Total+=i_t* (i_t+1); i_t++; } Else{ Total+=i_t; } } if(total== -) {printf ("%d", J); Flag=1; Break; } Else{ Total=Total_; }} FF=1; } Else{ Total+=i; } if(flag==1){ Break; } if(ff==1) { Total=0; FF=0; Break; } } if(flag==1){ Break; } } return 0;}
Answer: 16
13:25:54
2018-05-15
Addition variable multiplication--sixth annual Blue Bridge Cup C Language B group (provincial) sixth question