資料結構實驗之棧與佇列一:進位制轉換(SDUT 2131)
題解: 特判一下n==0的時候。
#include <bits/stdc++.h> using namespace std; int a[1000]; int main() { int top = 0; int n,r; scanf("%d",&n); scanf("%d",&r); if(n == 0) printf("0"); while(n) { a[top++] = n%r; n = n / r; } for(int i = top - 1; i >= 0; i --) { printf("%d",a[i]); } printf("\n"); return 0; }
相關推薦
資料結構實驗之棧與佇列一:進位制轉換(SDUT 2131)
題目連結 題解: 特判一下n==0的時候。 #include <bits/stdc++.h> using namespace std; int a[1000]; int main() {
資料結構實驗之棧與佇列一:進位制轉換
Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 輸入一個十進位制非負整數,將其轉換成對應的 R (2 <= R <= 9) 進位制數,並
[OJ.2131]資料結構實驗之棧與佇列一:進位制轉換
資料結構實驗之棧與佇列一:進位制轉換 Time Limit: 1000 ms
資料結構實驗之棧與佇列三:字尾式求值(SDUT 2133)
題解:把每一步計算的答案再存在棧裡面,直到計算結束。 如果是運算元 那麼直接入棧;如果是運算子,那麼把棧裡面最頂部的兩個運算元拿出來進行運算,運算結果再放入到棧裡面,計算完所有的(#
資料結構實驗之棧與佇列二:一般算術表示式轉換成字尾式(SDUT 2132)
題目連結 #include <bits/stdc++.h> using namespace std; typedef long long ll; int ok(char ch, char sh) { if(sh == '(')return 1; if((ch ==
【OJ.2132】資料結構實驗之棧與佇列二:一般算術表示式轉換成字尾式
資料結構實驗之棧與佇列二:一般算術表示式轉換成字尾式 Time Limit: 1000 ms
資料結構實驗之棧與佇列二:一般算術表示式轉換成字尾式 sdut-oj
#include <stdio.h> #include <stdlib.h> #define STACK_INIT_SIZE 100 #define STACKINCREMENT 100 typedef struct{ char *base;
資料結構實驗之二叉樹一:樹的同構 (SDUT 3340)
題解:把原本結構體的左右子樹的型別定義成 int 型,用來存放這個結點的左右子樹的編號,分別建造兩棵二叉樹,按個比較,如果在第二棵樹中沒有找到,那麼就不用在判斷了。 #include <bits/stdc++.h> using namespace std; struct node
資料結構實驗之棧與佇列六:下一較大值(二)(SDUT 3333)
#include <bits/stdc++.h> using namespace std; int a[1000006]; int b[1000006]; int sta[100006]; int main() { int t,n,i,j,top; while(~sc
資料結構實驗之棧與佇列五:下一較大值(一)(SDUT 3332)
#include <bits/stdc++.h> using namespace std; int a[1005]; int main() { int t,n,i,j; while(~scanf("%d",&t)) { while(t-
資料結構實驗之棧與佇列五:下一較大值(一)
資料結構實驗之棧與佇列五:下一較大值(一) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 對於包含n(1<=n<=1000)個整數的序列,對於序列中的每一元素,
資料結構實驗之棧與佇列五:下一較大值(一,二)
資料結構實驗之棧與佇列五:下一較大值(一,二) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 對於包含n(1<=n<=1000)個整數的序列,對於序
資料結構實驗之棧與佇列六:下一較大值(二)(因為資料量大所以用棧來操作)
資料結構實驗之棧與佇列六:下一較大值(二) Time Limit: 150 ms Memory Limit: 8000 KiB Problem Description 對於包含n(1<=n<=100000)個整數的序列,對於序列中的每一元素,在序列中查詢
資料結構實驗之棧與佇列六:下一較大值(二)
Time Limit: 150 ms Memory Limit: 8000 KiB Problem Description 對於包含n(1<=n<=100000)個整數的序列,對於序列中的每一元素,在序列中查詢其位置之後第一個大於它的值,如果找到,輸出所找到的
資料結構實驗之棧與佇列四:括號匹配(SDUT 2134)
#include <bits/stdc++.h> using namespace std; typedef long long ll; char s[100]; char a[100]; int main() { int i,j,k,f,top,len; while(
資料結構實驗之棧與佇列七:出棧序列判定
Problem Description 給一個初始的入棧序列,其次序即為元素的入棧次序,棧頂元素可以隨時出棧,每個元素只能入棧依次。輸入一個入棧序列,後面依次輸入多個序列,請判斷這些序列是否為所給入棧序列合法的出棧序列。 例如序列1,2,3,4,5是某棧的壓入順序,序列4
資料結構實驗之棧與佇列八:棧的基本操作
Problem Description 堆疊是一種基本的資料結構。堆疊具有兩種基本操作方式,push 和 pop。push一個值會將其壓入棧頂,而 pop 則會將棧頂的值彈出。現在我們就來驗證一下堆疊的
資料結構實驗之棧與佇列九:行編輯器
Problem Description 一個簡單的行編輯程式的功能是:接受使用者從終端輸入的程式或資料,並存入使用者的資料區。 由於使用者在終端上進行輸入時,不能保證不出差錯,因此,若在編輯程式中,“每接受一個字元即存入使用者資料區”的做法顯然不是最恰當的。較好
資料結構實驗之棧與佇列十:走迷宮
Problem Description 一個由n * m 個格子組成的迷宮,起點是(1, 1), 終點是(n, m),每次可以向上下左右四個方向任意走一步,並且有些格子是不能走動,求從起點到終點經過每個
資料結構實驗之棧與佇列八:棧的基本操作(new)
#include <stdio.h> #include <stdlib.h> typedef struct node { int *base; int *top; int stacksize; } sqstack;