| |

VerySource

 Forgot password?
 Register
Search
View: 1151|Reply: 7

Brother incompetence, begging for prawn guidance (with me learning C ++)

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-10 09:40:01
| Show all posts |Read mode
Digital encryption:
Claim. Encryption 0 ~ 9. Set the password corresponding to 0.1.2.3.4.5.6.7.8.9 to 9.0.8.2.7.4.6.3.1.5. Enter a four-digit number on the keyboard. It is required to output its corresponding password immediately. For example: Input 4925. Output: 7584
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-13 19:18:02
| Show all posts
This has nothing to do with the compilation. It is very simple. It was written in a few minutes without considering the efficiency. The input is four digits (less than four digits.
int main (int argc, char * argv [])
{//0.1.2.3.4.5.6.7.8.9 The corresponding password is 9.0.8.2.7.4.6.3.1.5
    int aa, n [4], num;

    cin >> aa;
    n [0] = aa% 10;
    n [1] = aa / 10% 10;
    n [2] = aa / 100% 10;
    n [3] = aa / 1000;

 for (int i = 0; i <= 3; i ++)
  {
    num = n [i];
    switch (num)
    {
     case 0: n [i] = 9; break;
     case 1: n [i] = 0; break;
     case 2: n [i] = 8; break;
     case 3: n [i] = 2; break;
     case 4: n [i] = 7; break;
     case 5: n [i] = 4; break;
     case 6: n [i] = 6; break;
     case 7: n [i] = 9; break;
     case 8: n [i] = 1; break;
     case 9: n [i] = 5; break;
     default: cout << "error";
    }
  }
  aa = n [0] + 10 * n [1] + 100 * n [2] + 1000 * n [3];
  cout << "Password is:";
  cout << aa;
   return 0;
}
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-14 20:54:01
| Show all posts
Requires assembly language. If I use C, I can write.
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-15 20:27:01
| Show all posts
The simple way is to use a mapping table, mapping once.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-1-16 13:54:01
| Show all posts
The easiest way:
Write a function that implements the change function, then F5 runs, set a breakpoint at the function entry, and then ALT + 8, copy the assembly generated by the compiler and it is OK
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-17 11:18:01
| Show all posts
According to your requirements, write and pull again. It should be fine.
data segment use16
 buf db 10
         db?
         db 10 dup (?), '$'
         
tab dw t0
        dw t1
dw t2
dw t3
dw t4
dw t5
dw t6
dw t7
dw t8
dw t9
data ends
code segment use16
           assume cs: code, ds: data
beg: mov ax, data
         mov ds, ax
         mov ah, 0Ah
         mov dx, offset buf
         int 21h
        lea bx, buf + 1
mov cx, 4
push bx
loo: pop bx
        inc bx
        sub byte ptr [bx], 30h
         push bx
      mov bl, byte ptr [bx]
        mov bh, 0
       add bx, bx
       mov si, offset tab
     dec cx
     cmp cx, 0
     je looo
       jmp [bx + si]
looo: mov dx, offset buf + 2
           mov ah, 09h
          int 21h

; The password corresponding to 0.1.2.3.4.5.6.7.8.9 is 9.0.8.2.7.4.6.3.1.5
t0: mov byte ptr [bx], 39h
       jmp loo
t1: mov byte ptr [bx], 30h
jmp loo
t2: mov byte ptr [bx], 38h
jmp loo
t3: mov byte ptr [bx], 32h
jmp loo
t4: mov byte ptr [bx], 37h
jmp loo
t5: mov byte ptr [bx], 34h
jmp loo
t6: mov byte ptr [bx], 36h
jmp loo
t7: mov byte ptr [bx], 33h
jmp loo
t8: mov byte ptr [bx], 31h
jmp loo
t9: mov byte ptr [bx], 35h
jmp loo
code ends
            end beg
Reply

Use magic Report

0

Threads

41

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-17 19:18:01
| Show all posts
C version
int main (int argc, char * argv [])
{
int sz [10] = {9,0,8,2,7,4,6,3,1,5};
char input [5] = {0};
scanf ("% 4s", input);
printf ("% d% d% d% d", sz [input [0]-'0'], sz [input [1]-'0'], sz [input [2]-'0'], sz [input [3]-'0']);
return 0;
}
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-15 16:00:01
| Show all posts
Thank you so much
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list