Oh ~~~ is this

xiaoxiao2021-03-06  73

#include #define maxsize 32typedef struct {int * elem; int max; int top;} stack;

INT INITSTACK (Stack * S, INT N) / * Initializes an empty set * / {S-> ELEM = (int *) malloc (n * sizeof (int)); if (S-> ELEM == Null) Return - 1; s-> max = n; s-> TOP = 0; return 0;}

INT PUSH (Stack * S, INT ITEM) / * Put the Item into the stack * / {if (S-> TOP == S-> max) {Printf ("stack is full! / n"); return -1;} S-> ELEM [S-> TOP ] = item; return 0;} int stackempty (stack s) / * The judgment stack is empty. Yes, return 1 * / {return ((! S.top)? 1: 0);

INT POP (stack * s) / * Put the top element outlet * / {if (! ") {Printf (" Pop An Empty Stack! / N "); Return-1;} Return S-> ELEM [--S-> TOP];

Void MultibaseOutput (long n, int b) / * converts 10 credit integer n to B-based number * / {INT M; Stack S; IF (INITSTACK (& S, MaxSize) {Printf ("Failure! / N" ); Return;} DO {IF (PUSH (& S, N% B)) {Printf ("Failure! / N"); return;} n = n / b;} while (n! = 0); while (! STACKEMPTY (S)) {m = POP (& S); if (M <10) Printf ("% D", M); Else Printf ("% C", M 55);}

}

#include long atoi (CHAR S [], int b) / * Transforms the string in s [] to B-based integers * / {INT I, N;

n = 0; for (i = 0; s [i]> = '0' && s [i] <= '9'; i) n = b * n (S [i] - '0'); return N;

Main () {Long M, B1, B2; INT i = 0; Char C; Char * SM, * SB1, * SB2;

Printf ("a $ ="); / * Enter m b * / for (c = getchar (); c! = '<'; c = getChar ()) / * Put the characters before '<' M, deposit in array SM [] * / sm [i ] = C; SM [i] = '/ 0'; for (c = getchar (), i = 0; C! = '>'; c = getchar ()) / * Put the characters between '<' and '>', deposits in SB1 [] * / sb1 [i ] = C; SB1 [i] = '/ 0';

For (c = getchar (), i = 0; c! = '/ n'; c = getchar ()) / * Put the characters before enter '>' Enter the number B, deposit SB2 [] * / SB2 [i ] = C; SB2 [I] = '/ 0';

B1 = ATOI (SB1, 10); / * Transforms the strings in SB1 into 10 enroll integers, and attached to B1 * / B2 = ATOI (SB2, 10); / * Transforms the string in SB2 to 10 Enter the integer and attached to B2 * / M = ATOI (SM, B1); / * converts the string in the SM into B1 enroll integers, and attached to M * / Printf ("% s <% s>%) s = ", SM, SB1, SB2); MULTIBASEOUTPUT (M, B2); / * Transform the integer M in B1, converted to B2, and output results * / printf (" <% ld> ", b2) GetCH ();

}

转载请注明原文地址:https://www.9cbs.com/read-93061.html

New Post(0)