4 条题解

  • 1
    @ 2025-12-4 16:54:33
    #include <stdio.h>
    int main(){
    	int n;
    	while (scanf ("%d",&n)!=EOF){
    		int a[100005];
    		int i=1;
    		if (n<3){
    			printf ("%d\n",n);
    			continue;
    	}
    	
    		while (n>=3){
    			a[i]=n%3;
    			i++;
    			n=n/3;
    		}
    	    a[i]=n;
    	    for (int j=i;j>=1;j--){
    	    	printf ("%d",a[j]);
    		}
    		printf ("\n");
    	}
    	return 0;
    }
    
    • 1
      @ 2024-11-30 14:06:48

      数据结构与算法 第二章栈与队列 c++

      #include <iostream>

      #include <stack>

      using namespace std;

      int main()

      {

      int n;

      while(cin>>n){

      int sum=0;

      stack<int>v;

      while(n>0){

      sum++;

      v.push(n%3);

      n/=3;

      }

      for(int i=0;i<sum;i++){

      cout<<v.top();

      v.pop();

      }

      cout<<endl;

      }

      return 0;

      }

      • @ 2024-11-30 14:39:44

        这个改进一些

        #include <iostream>

        #include <stack>

        using namespace std;

        int main()

        {

        int n;

        while (cin >> n) {

        stack<int>v;

        while (n > 0)

        v.push(n % 3);

        n /= 3;

        }

        while(v.size()) {

        cout << v.top();

        v.pop();

        }

        cout << endl;

        }

        return 0;

        }

      • @ 2025-3-22 15:23:30

        @ 纯c语言 #include <stdio.h>

        #define M 100

        typedef struct {

        int da[M];

        int top;

        } St;

        void cs(St* s) {

        s->top = -1;

        }

        void push(St* s, int v) {

        s->top++;

        s->da[s->top] = v;

        }

        void pop(St* s, int* v) {

        *v = s->da[s->top];

        s->top--;

        }

        void peek(St* s, int* v) {

        *v = s->da[s->top];

        }

        int main() {

        int a;

        while (scanf("%d", &a) != EOF) {

        St s;

        cs(&s);

        int cnt = 0;

        while (a > 0) {

        cnt++;

        push(&s, a % 3);

        a /= 3;

        }

        for (int i = 0; i < cnt; i++) {

        int v1, v2;

        peek(&s, &v1);

        printf("%d", v1);

        pop(&s, &v2);

        }

        printf("\n");

        }

        return 0;

        }

    • 0
      @ 2025-8-23 4:10:21
      from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
      while True:
          try:
              a, = re()
              s = ""
              while a:
                  s = str(a % 3) + s
                  a //= 3
              print(s)
          except:
              break
      
      • 0
        @ 2023-12-12 21:02:10
        #include <stdio.h>
        #include <string.h>
        
        int a[100]={0};	
        int main(){	
        	int n;
        	while(scanf("%d",&n)!=EOF){
        	for(int i=0;i<n;i++){
        		a[0]++;
        		for(int p=0;p<100;p++){
        			if(a[p]==3){
        				a[p]=0;
        				a[p+1]++;
        			}
        		}
        	}
        	int p=0;
        	for(int i=100;i>=0;i--){
        		if(a[i]!=0){
        			p=1;
        		}
        		if(p==1){
        			printf("%d",a[i]);
        		}
        	}
        	printf("\n");
        	memset(a,0,sizeof(a));
        }
        	return 0;
        }
        
        • 1

        信息

        ID
        223
        时间
        1000ms
        内存
        256MiB
        难度
        6
        标签
        递交数
        466
        已通过
        146
        上传者