// 1. First, determine the variable relationship, divide the problem into three dimensions, use the for statement nesting to build a loop framework // 2. Use the judgment Statement on the inner layer to determine the conditions that meet the problem // note that, set a variable for counting? # Include <iostream> using namespace STD; int main () {int m = 0; For (INT I = 1; I <= 100; I ++) {for (Int J = 1; j <= 100; j ++) {for (int K = 1; k <= 100; k ++) {If (I + J + k) = 100) & (3 * I + 2 * j + 0.5 * K) = 100 )) {cout <"Trojan:" <I <"Trojan:" <j <"Pony:" <K; m ++; cout <Endl ;}}}cout <"Total" <m <"group solution" <Endl; return 0 ;}
A similar problem occurs: How many exchange methods can I change my money into a coin (1 minute, 2 minutes, 5 minutes?
# Include <iostream> using namespace STD; int main () {int y = 100; int m = 0; For (INT I = 1; I <= y; I ++) {for (Int J = 1; j <= y; j ++) {for (int K = 1; k <= y; k ++) {if (I + 2 * j + 5 * k = y) {cout <"one cent:" <I <"two cent: "<j <" 5 cent: "<K; m ++; cout <Endl ;}}}} cout <"Total" <m <"exchange mode" <Endl; return 0 ;}