1 条题解
-
0
C :
#include<stdio.h> int main() { //freopen("in.txt","r",stdin); int n,i=0,j,x[1000],flag[1000]={0},fz[1000],sc[1000]; scanf("%d",&n); char c,d; getchar(); c=getchar(); while(d=getchar()) {if('0'<=d&&d<='9') x[i++]=d-'0';if(d==')') break;} for(i=0;i<n;i++) fz[i]=i; if(c=='A') { for(i=0;i<n;i++) { int count=0; for(j=0;j<i;j++) if(x[j]<x[i]) ++count; sc[i]=count; } printf("B=("); for(i=0;i<n;i++) if(i!=n-1) printf("%d,",sc[i]);else printf("%d)\n",sc[i]); } else { for(i=n-1;i>=0;i--) { int j=0,count =0; for(count;count<=x[i];) { if(flag[j++]==0) count++; } sc[i]=fz[j-1];flag[j-1]=1; } printf("A=("); for(i=0;i<n;i++) if(i!=n-1) printf("%d,",sc[i]);else printf("%d)\n",sc[i]); } return 0; }
C++ :
#include<stdio.h> int main() { //freopen("in.txt","r",stdin); int n,i=0,j,x[1000],flag[1000]={0},fz[1000],sc[1000]; scanf("%d",&n); char c,d; getchar(); c=getchar(); while(d=getchar()) {if('0'<=d&&d<='9') x[i++]=d-'0';if(d==')') break;} for(i=0;i<n;i++) fz[i]=i; if(c=='A') { for(i=0;i<n;i++) { int count=0; for(j=0;j<i;j++) if(x[j]<x[i]) ++count; sc[i]=count; } printf("B=("); for(i=0;i<n;i++) if(i!=n-1) printf("%d,",sc[i]);else printf("%d)\n",sc[i]); } else { for(i=n-1;i>=0;i--) { int j=0,count =0; for(count;count<=x[i];) { if(flag[j++]==0) count++; } sc[i]=fz[j-1];flag[j-1]=1; } printf("A=("); for(i=0;i<n;i++) if(i!=n-1) printf("%d,",sc[i]);else printf("%d)\n",sc[i]); } return 0; }
Python :
def fmin(a, n): a.sort() return a.pop(int(n)) def func(a): s = "" if a[0] == "A": s = "B=(0," for x in xrange(1,len(a[1])): c = 0 for i in xrange(0,x): c += a[1][i] < a[1][x] s += str(c) + [')', ','][x < len(a[1]) - 1] elif a[0] == "B": s = "A=(" t = [] b = [i for i in xrange(0, len(a[1]))] for x in xrange(len(a[1]) - 1, -1, -1): t.append(fmin(b, a[1][x])) t.reverse() for x in xrange(0,len(t)): s += str(t[x]) + [')', ','][x < len(t) - 1] return s n = raw_input() while (n): s = raw_input() a = [s[0], s[3:len(s) - 1].split(",")] print func(a) n = raw_input()
- 1
信息
- ID
- 168
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 0
- 上传者