The question requires that all valid locations of "" (a) and "" (B) be output, and only one byte storage variable can be used;
Solution 1:
1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int i=81; 7 while(i--) 8 { 9 if(i/9%3==i%9%3)10 continue;11 else12 cout<<i/9+1<<‘\t‘<<i%9+1<<endl;13 }14 return 0;15 }
View code
There are nine methods for a and B, So I = 81, for an integer I = I/9*9 + I % 9; I % 9 with I/9 change round, it is equivalent to a nested loop; an I is used to represent the changes of two values;
Of course, you can also use this method to implement multiple nesting;
Solution 2:
1 #include<iostream> 2 using namespace std; 3 4 struct myBite 5 { 6 unsigned char a:4; 7 unsigned char b:4; 8 }; 9 10 int main(void)11 {12 myBite i;13 for(i.a=1;i.a<=9;++i.a)14 for(i.b=1;i.b<=9;++i.b)15 if(i.a%3!=i.b%3)16 cout<<(int)i.a<<‘\t‘<<(int)i.b<<endl;17 return 0;18 }
View code
Refer to related bit operations
The beauty of programming-question about Chinese chess masters