问题标题: 酷町堂:3827

0
0
已解决
邵悦媛
邵悦媛
新手光能
新手光能

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[200010];
bool cmp(string a,string b)
{
    if(a[a.size()-1]!=b[b.size()-1])
        return a[a.size()-1]>b[b.size()-1];
    else if(a.size()!=b.size())
        return a.size()<b.size();
    return a<b;
}
int main(){
int n;
cin>>n;
double t;
for(int i=1;i<=n;i++){
cin>>t;
a[(int)t]++;
}
for(double i=1;i<=n;i++){
for(int j=1;j<=a[(int)i];j++){
cout<<i<<endl;
}
}
return 0;
}

怎么错了???


0
已采纳
朱家烨
朱家烨
资深守护
资深守护
  • int a[10000000];
  • bool cmp(自己想){
  • if(自己想) return 自己想;
  • return x<y;
  • }
  • int main(){
  • int n;
  • cin>>n;
  • for(自己想) cin>>a[i];
  • sort(你应该会);
  • for(自己想) cout<<a[i]<<endl;
朱家烨在2020-08-16 12:16:02追加了内容

不谢

 

只求豆豆

0
吴文光
吴文光
新手光能
新手光能
bool cmp(int a,int b)
{
    if(a%10!=b%10)
    {
        return a%10>b%10;
    }
    return a<b;
}
这是cmp函数
首先,全局定义数组a要定义的比较大。在主函数内定义n(long long)输入n,然后for给a循环定义sort给a+
到a+n+1排序,sort(a+1,a+n+1,cmp);最后输出a数组
for(int i=1;i<=n;i++)
    cout<<a[i]<<endl;

 

吴文光在2020-08-16 14:28:56追加了内容

望采纳

0
0
赵泰来
赵泰来
高级光能
高级光能
  • bool cmp(int a,int b){
  • if(a%10!=b%10){
  • return a%10>b%10;
  • }
  • return a<b;
  • }
  • 函数

cin

sort(a+0,a+0+n,cmp);

然后 cout;

 

0
杜智宸
杜智宸
中级光能
中级光能

不需要那么麻烦啦

cmp函数其他回答都有,我就不写了

输入n和a[i],然后:

  • sort(a+1,a+n+1,cmp);
  • for(int i=1;i<=n;i++)
  • cout<<a[i]<<endl;

就没了

等你飞鸿

0
陈振轩
陈振轩
高级光能
高级光能

CMP函数不要太麻烦了

    if(a%10!=b%10)
        return a%10>b%10;
    return a<b;

况且,你有写sort函数吗?

0
江齐悦
江齐悦
高级光能
高级光能

这是函数:

bool cmp(int a,int b) {

if如果(a%10 不等于 b%10)

return a%10 大于 b%10;

return a<b;

}

这是主函数:

int a[20001];

int main() {

int n;

cin >> n;

for(int i=1; i<=n; i++ ) {

cin >> a[i];

}

sort(a+1, a+1+n, cmp);

for(int i=1; i<=n; i++) cout << a[i] << endl;

}

别忘了return 0;

望采纳

哦,对了,记得要加#include <algorithm>哦。

我要回答