zoukankan      html  css  js  c++  java
  • ZOJ_3501 Roman Order

      这题应该是个水题,可是我比题还水。。。TT,用map写的,存对应的roma数字时存错啦。。。正好在比赛,我晕,WA了两次,我的排名啊。。。TT

    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <map>

    using namespace std;

    map
    <int, string> m;

    struct roma
    {
    int x;
    string s;
    }roma[
    10010];

    void init()
    {
    m[
    1] = "I";m[2] = "II";m[3] = "III";m[4] = "IV";
    m[
    5] = "V";m[6] = "VI";m[7] = "VII";m[8] = "VIII";
    m[
    9] = "IX";m[10] = "X";m[20] = "XX";m[30] = "XXX";
    m[
    40] = "XL";m[50] = "L"; m[60] = "LX"; m[70] = "LXX";m[80] = "LXXX";
    m[
    90] = "XC";m[100] = "C"; m[200] = "CC";m[300] = "CCC";
    m[
    400] = "CD"; m[500] = "D"; m[600] = "DC"; m[700] = "DCC";
    m[
    800] = "DCCC"; m[900] = "CM"; m[1000] = "M"; m[2000] = "MM";
    m[
    3000] = "MMM";
    }

    int cmp ( const void * a , const void * b )
    {
    struct roma *c = (struct roma *)a;
    struct roma *d = (struct roma *)b;
    return c->s > d->s;
    }

    int main()
    {
    //freopen("data.in", "r", stdin);

    int t, n, i, f, tmp;
    init();
    string str;

    while(scanf("%d", &t) != EOF)
    {
    while(t--)
    {
    scanf(
    "%d", &n);
    for(i = 0; i < n; i++)
    {
    scanf(
    "%d", &f);
    tmp
    = f;
    str.clear();
    if(f/1000)
    {
    str
    += m[(f/1000)*1000];
    f
    %= 1000;
    }
    if(f/100)
    {
    str
    += m[(f/100)*100];
    f
    %= 100;
    }
    if(f/10)
    {
    str
    += m[(f/10)*10];
    f
    %= 10;
    }
    if(f)
    {
    str
    += m[f];
    }
    roma[i].x
    = tmp;
    roma[i].s.clear();
    roma[i].s
    = str;
    }

    qsort(roma, n,
    sizeof(roma[0]), cmp);

    for(i = 0; i < n-1; i++)
    {
    printf(
    "%d ", roma[i].x);
    //cout << roma[i].s << " " ;
    }
    printf(
    "%d\n", roma[n-1].x);
    //cout << roma[i].s << endl;
    }
    }
    return 0;
    }
  • 相关阅读:
    2019-05-07
    2019-04-28 问题记录
    2019-04-15 python深浅复制
    2019-04-11 统计日志重复数量
    2019-03-23 shell练习,日志统计
    问题记录2019-03-12
    问题记录2019-03-06(todo)
    回归
    Mac进行 usr/bin 目录下修改权限问题,operation not permitted
    个人的随笔心情
  • 原文地址:https://www.cnblogs.com/vongang/p/2179732.html
Copyright © 2011-2022 走看看