2956. Maya历日期的排序

Zoey

有人没有AC是因为把月份表示单词输错字母了吗。。。。。别犯这种大意的错误,检查好久才检查出来。没AC的小伙伴可以看一下是不是这个原因导致的

Fifnmar

就一个注意的地方,就是那个比较函数。

让我试试压压行(滑稽)

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

const unordered_map<string, int> months{
    {"pop", 1},  {"no", 2},     {"zip", 3},    {"zotz", 4},    {"tzec", 5},
    {"xul", 6},  {"yoxkin", 7}, {"mol", 8},    {"chen", 9},    {"yax", 10},
    {"zac", 11}, {"ceh", 12},   {"mac", 13},   {"kankin", 14}, {"muan", 15},
    {"pax", 16}, {"koyab", 17}, {"cumhu", 18}, {"uayet", 19},
};

struct Maya {
    string data[3];
} rec[10000];

int main() {
    int t; cin >> t;
    for (int query = 0; query < t; ++query) {
        int n; cin >> n;
        for (int i = 0; i < n; ++i)
            cin >> rec[i].data[0] >> rec[i].data[1] >> rec[i].data[2];
        sort(rec, rec + n, [](Maya const &a, Maya const &b) {
            if (a.data[2] == b.data[2]) {
                if (a.data[1] == b.data[1]) {
                    if (a.data[0].size() == b.data[0].size())
                        return a.data[0] < b.data[0];
                    else
                        return a.data[0].size() < b.data[0].size();
                } else
                    return months.at(a.data[1]) < months.at(b.data[1]);
            } else
                return a.data[2] < b.data[2];
        });
        cout << "case #" << query << ":\n";
        for (int i = 0; i < n; ++i)
            cout << rec[i].data[0] << ' ' << rec[i].data[1] << ' ' << rec[i].data[2] << '\n';
    }
}
Garin1029

麻了,在定义string Month[19] = {
“pop”,”no”, “zip”, “zotz”, “tzec”, “xul”,”yoxkin”,”mol”, “chen”,
“yax”, “zac”, “ceh”, “mac”, “kankin”, “muan”,”pax”,”koyab”, “cumhu”,”uayet”
};的时候手贱有两个月份多打了空格,查错查了1个小时。
空格,yyds

Garin1029

我是伞兵

NBC++

cumhu 抄成 cumbu,检查了好久没看出来.....

Li Dao

WA了25次之后的人生经验

include

using namespace std;
int T,n;
const string DIC[22]={“pop”, “no”, “zip”, “zotz”, “tzec”, “xul”, “yoxkin”, “mol”, “chen”, “yax”, “zac”, “ceh”, “mac”, “kankin”, “muan”, “pax”, “koyab”, “cumhu”,”uayet”};

struct Date
{
string day,month,year;
};
vector V;

int getIndex(const string& strs)
{
for(int i=0;i<20;i++) if(DIC[i]==strs) return i;
}

int daycmp(const string& d1,const string& d2)
{
if(d1.length()!=d2.length()) return d1.length()<d2.length();
else return d1<d2;
}

int cmp(const Date& aa,const Date& bb)
{
if(aa.year!=bb.year) return aa.year<bb.year;
else if(aa.month!=bb.month) return getIndex(aa.month)<getIndex(bb.month);
else return daycmp(aa.day,bb.day);
}

int main()
{
std::ios::sync_with_stdio(false);
cin>>T;
for(int step=0;step>n;
V.clear();
for(int i=1;i<=n;i++)
{
string a,b,c;
cin>>a>>b>>c;
V.push_back((Date){a,b,c});
}
sort(V.begin(),V.end(),cmp);
cout<<”case #”<<step<<”:”<<endl;
for(int i=0;i<V.size();i++)
cout<<V[i].day<<’ ‘<<V[i].month<<’ ‘<<V[i].year<<endl;
}
return 0;
}

用了std::ios::sync_with_stdio(false);关闭流同步,来加速之后,cin,cout,scanf,printf不能混用,否则会错位

以下是c程序:

include

using namespace std;
char m[22][20]={“pop”, “no”, “zip”, “zotz”, “tzec”, “xul”, “yoxkin”, “mol”, “chen”, “yax”, “zac”, “ceh”, “mac”, “kankin”, “muan”, “pax”, “koyab”, “cumhu”,”uayet”};
struct date{
int y,d,m,dd;
} a[10010];
char s[300];
void read(int i){
scanf(“%d”,&a[i].d);
char c;
scanf(“%c”,&c);
scanf(“%s”,s);
int ii;
for (ii=0;ii<20;ii++) if (strcmp(m[ii],s)==0) break;
a[i].m=ii;
scanf(“%d”,&a[i].y);
a[i].dd=a[i].d;
for (int ii=0;ii<a[i].m;ii++) a[i].dd+=20;
}
bool cmp(date p1,date p2){
return (p1.y<p2.y || (p1.y==p2.y && p1.dd<p2.dd));
}
int main()
{
int T,n;
scanf(“%d”,&T);
for (int ii=0;ii<T;ii++){
scanf(“%d”,&n);
for (int i=0;i<n;i++) read(i);
sort(a,a+n,cmp);
printf(“case #%d:\n”,ii);
for (int i=0;i<n;i++) printf(“%d. %s %d\n”,a[i].d,m[a[i].m],a[i].y);
}
}

两个程序都是AC的

你当前正在回复 博客/题目
存在问题!