1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 typedef int Status; typedef struct StackNode { int data; struct StackNode *next; }StackNode; typedef struct Stack { StackNode *top; }Stack; Status InitStack(Stack *s) { s->top=NULL; return OK; } Status Push(Stack *s,int e) { StackNode *newnode=(StackNode *)malloc(sizeof(StackNode)); newnode->data=e; newnode->next=s->top; s->top=newnode; return OK; } Status Pop(Stack *s,int *e) { if(s->top==NULL) return ERROR; *e=s->top->data; return OK; } Status StackEmpty(Stack s) { if(s.top==NULL) return OK; return ERROR; } Status DestroyStack(Stack *s) { StackNode *p; p=s->top; s->top=s->top->next; free(p); return OK; } int main() { int N,e; Stack s; while(scanf("%d",&N)!=EOF) { if(N==0) printf("0"); InitStack(&s); while(N) { Push(&s,N%8); N/=8; } while(!StackEmpty(s)) { Pop(&s,&e); printf("%d",e); DestroyStack(&s); } printf("\n"); } return 0; }
C++ :
#include<stdio.h> int main() { int n,a[10],i,k; while(scanf("%d",&n)!=EOF) { if(!n) { puts("0"); continue; } k=0; while(n) { a[k++]=n%8; n/=8; } for(i=k-1;i>=0;i--) printf("%d",a[i]); puts(""); } return 0; }
Pascal :
var n,i,j:longint; a:array[1..10000] of longint; begin while not eof do begin readln(n);i:=0; if n=0 then write(0); while n<>0 do begin inc(i); a[i]:=n mod 8; n:=n div 8; end; for j:=i downto 1 do write(a[j]); writeln; end; end.
Java :
import java.util.*; public class Main { public static void main(String[] args) { int a,b,n; Stack<Integer> s = new Stack<Integer>(); Scanner cin=new Scanner(System.in); while(cin.hasNext()) { n=cin.nextInt(); if(n==0) System.out.print("0"); while(n>0) { s.push(n%8); n=n/8; } while(s.empty()!=true) { System.out.print(s.peek()); s.pop(); } System.out.print("\n"); } cin.close(); } }
- 1
信息
- ID
- 1129
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者