6 条题解
-
3
(⊙﹏⊙)
#include<bits/stdc++.h> using namespace std; int a[100000]; int main() { int k=1; while( cin >>a[k] ){ k++; } k--; for(int i=k; i>1; i--){ for(int j=1; j<i; j++){ if(a[j]<a[j+1]){ swap(a[j],a[j+1]); } } } for(int i=1; i<=k; i++){ cout<<a[i]<<" "; } return 0; }
朴实无华
-
3
读入比较麻烦可以不采纳 其他思想就是归并排序的归并部分
#include <bits/stdc++.h> using namespace std; typedef vector<int> vin; vin a,b,c; int main() { string s1,s2; getline(cin,s1); getline(cin,s2); stringstream ss1(s1); stringstream ss2(s2); int t; while(ss1 >> t) a.push_back(t); while(ss2 >> t) b.push_back(t); int l = 0,r = 0; while(l<a.size() && r<b.size()) { if(a[l]>=b[r]) c.push_back(a[l++]); else c.push_back(b[r++]); } while(l<a.size()) c.push_back(a[l++]); while(r<b.size()) c.push_back(b[r++]); for(auto x:c) cout << x << " "; return 0; }
-
2
def display(a,head): p = head while a[p][1]!=-1: print(a[p][0],end = " ") p = a[p][1] print(a[p][0]) def insert(x,a): global head p = head if x>=a[p][0]: a.append([x,head]) head = len(a)-1 else: while a[p][1]!=-1 and a[a[p][1]][0]>=x: p = a[p][1] a.append([x,a[p][1]]) a[p][1] = len(a)-1 s = list(map(int,input().split())) a = [];cnt=1 for i in s: a.append([i,cnt]) cnt+=1 a[-1][1] = -1 head = 0 s2 = list(map(int,input().split())) for i in s2: insert(i,a) display(a,head)
-
2
python过了,但是没有完全过
a=input().split() b=input().split() a.sort() b.sort() c=[] y=0 for i in a: c.append(i) for i in b: c.append(i) for i in c: y=y+1 #c=["9","6","7","4","2","5","1","40","8","30","32","44","28","26","3","2","1"] #y=17 for i in c: x=c.index(i) xx=x+1 z1=int(c[x]) w=1 if y>xx: z2=int(c[xx]) while y>xx and z1<z2 and x>=0 and w==1: z1=int(c[x]) z2=int(c[xx]) if z1>z2: w=0 break c[x]=z2 c[xx]=z1 x=x-1 xx=xx-1 for i in c: print(i,end=" ")
不知道错在哪了...
(给我过啊!!!) -
1
链表实现 理解难度低
class Node: def __init__(self,val:int,nxt:int): self.val=val self.nxt=nxt def add (it,val): o.append(Node(val,o[it].nxt)) o[it].nxt=len(o)-1 def delete (it): o[it].nxt=o[o[it].nxt].nxt a=list(map(int,input().split())) b=list(map(int,input().split())) if a[0]>b[0]: a,b=b,a o=[Node(b[i],i+1) for i in range(len(b))] o[len(b)-1].nxt=-1 i=0 j=0 while i<len(a) and o[j].nxt!=-1: if a[i]<o[j].val and a[i]>=o[o[j].nxt].val: add(j,a[i]) i+=1 else: j=o[j].nxt while i < len(a):#找到尾节点 it=0 while o[it].nxt!=-1: it=o[it].nxt add(it,a[i]) i+=1 it=0 while it!=-1: print(o[it].val,end=" ") it=o[it].nxt
- 1
信息
- ID
- 768
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 482
- 已通过
- 219
- 上传者