Home > Back-end >  In asking bosses told
In asking bosses told

Time:03-28

. Our encrypted message is composed of eight basic characters, respectively is A B C D # 1 2 3, for long-distance transmission, now need to transfer encoding of the eight characters, transfer encoding with binary encoding (long-distance transmission, digital code anti-interference ability strong), the binary coding for three long code (all characters coding length), coding rules are as follows:
A: 000 B: 001 C, 010 D, 011 1:100 2:10 3:11 0 # 1:111
Now enter a line (up to 10) to encrypt the message code, please translate it for the corresponding transfer encoding and output,
For example: input ABC#, output 000001010111,
Tip: encoding rules can be stored in an array, become the code table,
Format remind:
Input: input from A B C D 1 2 3 # of A line of characters, # can only appear in the end, after the carriage returns,
Output: a line of binary code, the last carriage returns, pay attention to the 0 s and 1 s of binary encoding is character, not Numbers,

CodePudding user response:

The teacher the assignment.
 
//A: 000 B: 001 C, 010 D, 011 1:100 2:10 3:11 0 # 1:111
#include
#include

Int main (int arg c, char * argv [])
{
Char mess [12].

The scanf (" % s ", mess);

for (int i=0; i {
The switch (mess [I])
{
Case 'A' :
Printf (" 000 ");
break;

Case 'B' :
Printf (" 001 ");
break;

Case 'C' :
Printf (" 010 ");

Case 'D' :
Printf (" 011 ");
break;

Case '1' :
Printf (" 100 ");
break;

Case '2' :
Printf (" 101 ");
break;

Case '3' :
Printf (" 110 ");
break;

Case '#' :
Printf (" 111 ");
return 0;

Default:
break;
}
}

return 0;
}

CodePudding user response:

When # under a new line

CodePudding user response:

Reference:
 # include & lt; stdio.h> 
#include

Int main ()
{//A B C D 1 2 3 #
Char [s] [4]={" 000 ", "001", "010", "011", "100", "101", "110", "111"};
Char STR, PTR [64];

Do {
The scanf (" % c ", & amp; STR);
The switch (STR) {
Case 'A' : strcat (PTR, s [0]).
break;
Case 'B' : strcat (PTR, s [1]).
break;
Case 'C' : strcat (PTR, s [2]).
break;
Case 'D' : strcat (PTR, s [3]).
break;
Case '1' : strcat (PTR, s [4]);
break;
Case '2' : strcat (PTR, s [5]);
break;
Case: '3' strcat (PTR, s [6]);
break;
Case '#' : strcat (PTR, s [7]);
break;
Default: break;
}
} while (STR!='#');
Printf (" % s \ n ", PTR);

return 0;
}

CodePudding user response:

reference 1/f, Kira Skyler response:
teacher assigned homework.
 
//A: 000 B: 001 C, 010 D, 011 1:100 2:10 3:11 0 # 1:111
#include
#include

Int main (int arg c, char * argv [])
{
Char mess [12].

The scanf (" % s ", mess);

for (int i=0; i {
The switch (mess [I])
{
Case 'A' :
Printf (" 000 ");
break;

Case 'B' :
Printf (" 001 ");
break;

Case 'C' :
Printf (" 010 ");

Case 'D' :
Printf (" 011 ");
break;

Case '1' :
Printf (" 100 ");
break;

Case '2' :
Printf (" 101 ");
break;

Case '3' :
Printf (" 110 ");
break;

Case '#' :
Printf (" 111 ");
return 0;

Default:
break;
}
}

return 0;
}

In c + + how to write, we don't learn c language

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
for reference:
 # include & lt; stdio.h> 
#include

Int main ()
{//A B C D 1 2 3 #
Char [s] [4]={" 000 ", "001", "010", "011", "100", "101", "110", "111"};
Char STR, PTR [64];

Do {
The scanf (" % c ", & amp; STR);
The switch (STR) {
Case 'A' : strcat (PTR, s [0]).
break;
Case 'B' : strcat (PTR, s [1]).
break;
Case 'C' : strcat (PTR, s [2]).
break;
Case 'D' : strcat (PTR, s [3]).
break;
Case '1' : strcat (PTR, s [4]);
break;
Case '2' : strcat (PTR, s [5]);
break;
Case: '3' strcat (PTR, s [6]);
break;
Case '#' : strcat (PTR, s [7]);
break;
Default: break;
}
} while (STR!='#');
Printf (" % s \ n ", PTR);

return 0;
}

In c + + how to write, we don't learn c language

CodePudding user response:

Header file modification: # include & lt; Iostream. H>
#include
using namespace std;

Then type: cin> STR;//the scanf (" % c ", & amp; STR);
Output: coutOther are all the same, need not be changed,

CodePudding user response:

reference 5 floor _ClutchFactor reply:
Quote: refer to the third floor QZJHJXJ response:
for reference:
 # include & lt; stdio.h> 
#include

Int main ()
{//A B C D 1 2 3 #
Char [s] [4]={" 000 ", "001", "010", "011", "100", "101", "110", "111"};
Char STR, PTR [64];

Do {
The scanf (" % c ", & amp; STR);
The switch (STR) {
Case 'A' : strcat (PTR, s [0]).
break;
Case 'B' : strcat (PTR, s [1]).
break;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related