萌新求助,求dalao看看程序。

P1897 电梯里的尴尬

很有可能是getchar的问题 ```cpp #include<iostream> #include<cstdio> using namespace std; int main() { int a=0,i,j,t,g,jmax=0,y; int b[100000],c[100000]; //printf(""); cin>>a; for(int i=0;i<a;i++) cin>>b[i]; for(j=0;j<a;j++){ if(b[j]>b[jmax]){ jmax=j;} } t=b[jmax]*10; for(j=0;j<a;j++){ c[j]=b[j]; t=t+6; for(g=j;g<a;g++){ if(c[j]==b[g]){ t=t+1; } } } printf("%d",t); return 0; } ``` 我把输出空格注释掉了,因为不知道是用来干什么的 然后把输入数组b改成如上形式,不过还是不对,7个WA3个TLE 如果评测的时候用时12000ms,那很有可能是getchar出锅了,因为我也碰到过
by 冬瓜皮 @ 2018-10-24 23:17:39


```cpp #include<cstdio> #include<algorithm> using namespace std; int main() { int all=0,q=0,ans=0,n,a[100001],i,first=1; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n); while(q!=n) if(all==a[q+1]) { if(first) ans+=5,first=0; ans+=1; q++; } else { all++; ans+=6; first=1; } printf("%d",ans+all*4); return 0; } ``` ~~很水的一道题~~蒟蒻的我打了5分钟 代码自己看吧
by resftlmuttmotw @ 2018-10-24 23:22:54


@[冬瓜皮](/space/show?uid=92287) qwq请问一下dalao超时的问题要怎么解决呢萌新不是很懂这种数组的输入
by a126180088 @ 2018-10-25 14:36:24


@[a126180088](/space/show?uid=140839) dalao不敢当,难道不是cin或者scanf就可以了吗?
by 冬瓜皮 @ 2018-10-25 21:27:54


@[冬瓜皮](/space/show?uid=92287) qwq,dalao问一下,scanf要怎么输入这种数组呢qwq,他题目给的输入形式是数加空格加数,貌似不能用循环输出吧
by a126180088 @ 2018-10-26 11:54:27


@[a126180088](/space/show?uid=140839) 输入的时候程序难道不会忽略空格吗QAQ 输入的数据肯定会有空格啊不然怎么把两个数分开 ```c for (int i=0;i<n;i++){ scanf ("%d",&a);//每次读一个人 ``` 这是从某题解里摘的一段,显然空格是不需要处理的,我记得应该只有gets会读入空格,它是读一行。用cin和scanf读入任何类型的数据应该都是到空格结束,跳过空格去读下一个吧
by 冬瓜皮 @ 2018-10-26 12:28:27


@[冬瓜皮](/space/show?uid=92287) 哦哦!qwq谢谢dalao的讲解
by a126180088 @ 2018-10-26 12:45:44


@[a126180088](/space/show?uid=140839) 你可以自己写读入程序,用get写(如果你对cin,scanf不满意的话)
by 孤独的死男孩 @ 2019-10-14 22:19:58


|