Yesterday, a classmate talked to me about an ACM question, which was very interesting. As a result, I listened to the question's requirements:
Enter two numbers in each line as follows:
1 1234567890
Output:
2 1234567890
Output
3 1234567890
Output
I think you should know the requirements of the questions.
Analysis: The above digital output is a bit like LED digital output. I don't know if you know the seven-segment LED display. I used this in my program below, if each bit of storage is enabled, 0 indicates that the storage is not enabled, and 1 indicates that the storage is enabled.
As follows:
The above 0-6 corresponds to the LED segment, with a total of 7 segments, so we can use 7 bits to store them separately. 0 indicates none, and 1 indicates there are
For example, 2 is displayed
We can use the following binary representation (from the 6-0 order) to 1011101; similarly, the binary representation of 3 is 1101101; the binary representation of 4 is 0101110. With the above analysis, in the output. Only I = 0 \ 3 \ 6 indicates horizontal, and the rest indicates vertical, and their output is different. If a bit is set, the corresponding flag is output. If no bit is set, a space is output. The Code is as follows:
[Cpp]
# Include <iostream>
# Include <string>
# Include <vector>
/**
Author: w31690770
E-mail: wyphao.2007@163.com
It is only used for learning and communication. For more information, please write the above comments. Thank you for your kindness.
*/
Using namespace std;
Char ptr [] = {
// These numbers indicate 0-9 LED Display
119, 36, 93,109, 46,107,123, 37,127,111
};
Bool getBit (char c, int I ){
Return c & (1 <I );
}
Int main (){
String num= "1234890 ";
Int n = 3;
Int len = 0;
Len = num. length ();
// Save the numeric representation above
Vector <char> v;
Int I = 0;
For (I = 0; I <len; I ++ ){
V. push_back (ptr [num [I]-'0']);
// Cout <(int) v [I] <endl;
}
// Whether it is horizontal
Bool isH = false;
Int j = 0, k = 0, l = 0;
For (I = 0; I <7; I ++ ){
// Horizontal
For (j = 0; j <len; j ++ ){
For (k = 0; k <n + 2; k ++ ){
If (I = 0 | I = 3 | I = 6 ){
IsH = true;
} Else {
IsH = false;
}
If (isH & (k = 0 | k = n + 1 )){
Cout <"";
} Else if (I = 0 | I = 3 | I = 6) & getBit (v [j], I )){
Cout <"-";
} Else if (I = 0 | I = 3 | I = 6 )&&! GetBit (v [j], I )){
Cout <"";
}
}
}
// Vertical
For (k = 0; k <n; k ++ ){
For (j = 0; j <len; j ++ ){
If (I = 1 | I = 4) & getBit (v [j], I )){
Cout <"| ";
For (l = 0; l <n; l ++ ){
Cout <"";
}
} Else if (I = 1 | I = 4 )&&! GetBit (v [j], I )){
Cout <"";
For (l = 0; l <n; l ++ ){
Cout <"";
}
}
If (I + 1) = 2 | (I + 1) = 5) & getBit (v [j], I + 1 )){
Cout <"| ";
} Else if (I + 1) = 2 | (I + 1) = 5 )&&! GetBit (v [j], I + 1 )){
Cout <"";
}
}
If (! IsH ){
Cout <endl;
}
}
// Output, So skip
If (I = 1 | I = 4 ){
I ++;
} Else {
Cout <endl;
}
}
Cout <endl;
Return 0;
}
# Include <iostream>
# Include <string>
# Include <vector>
/**
Author: w31690770
E-mail: wyphao.2007@163.com
It is only used for learning and communication. For more information, please write the above comments. Thank you for your kindness.
*/
Using namespace std;
Char ptr [] = {
// These numbers indicate 0-9 LED Display
119, 36, 93,109, 46,107,123, 37,127,111
};
Bool getBit (char c, int I ){
Return c & (1 <I );
}
Int main (){
String num= "1234890 ";
Int n = 3;
Int len = 0;
Len = num. length ();
// Save the numeric representation above
Vector <char> v;
Int I = 0;
For (I = 0; I <len; I ++ ){
V. push_back (ptr [num [I]-'0']);
// Cout <(int) v [I] <endl;
}
// Whether it is horizontal
Bool isH = false;
Int j = 0, k = 0, l = 0;
For (I = 0; I <7; I ++ ){
// Horizontal
For (j = 0; j <len; j ++ ){
For (k = 0; k <n + 2; k ++ ){
If (I = 0 | I = 3 | I = 6 ){
IsH = true;
} Else {
IsH = false;
}
If (isH & (k = 0 | k = n + 1 )){
Cout <"";
} Else if (I = 0 | I = 3 | I = 6) & getBit (v [j], I )){
Cout <"-";
} Else if (I = 0 | I = 3 | I = 6 )&&! GetBit (v [j], I )){
Cout <"";
}
}
}
// Vertical
For (k = 0; k <n; k ++ ){
For (j = 0; j <len; j ++ ){
If (I = 1 | I = 4) & getBit (v [j], I )){
Cout <"| ";
For (l = 0; l <n; l ++ ){
Cout <"";
}
} Else if (I = 1 | I = 4 )&&! GetBit (v [j], I )){
Cout <"";
For (l = 0; l <n; l ++ ){
Cout <"";
}
}
If (I + 1) = 2 | (I + 1) = 5) & getBit (v [j], I + 1 )){
Cout <"| ";
} Else if (I + 1) = 2 | (I + 1) = 5 )&&! GetBit (v [j], I + 1 )){
Cout <"";
}
}
If (! IsH ){
Cout <endl;
}
}
// Output, So skip
If (I = 1 | I = 4 ){
I ++;
} Else {
Cout <endl;
}
}
Cout <endl;
Return 0;
}
Output: