鱼C论坛

 找回密码
 立即注册
查看: 1890|回复: 0

求帮助我简化代码并指导一下我

[复制链接]
发表于 2018-1-5 16:15:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 阴阳神万物主 于 2020-1-3 15:30 编辑
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
int main()
{
        freopen("filenamein.txt","r",stdin);
        freopen("filenameout.txt","w",stdout);
        freopen("filenamerr.txt","w",stderr);
    int N; // Number of elements which make up the association table.
    cin >> N; cin.ignore();cerr<<N<<endl;
    int Q; // Number Q of file names to be analyzed.
    cin >> Q; cin.ignore();cerr<<Q<<endl;
    string EXT[10000]; // file extension
    string MT[10000];// MIME type.
    for (int i = 0; i < N; i++) {
        cin >> EXT[i] >> MT[i]; cin.ignore();
        for(int b=0;b<EXT[i].length();b++)
        {
            if(isupper(EXT[i][b]))EXT[i][b]+=32;
            }
        cerr<<"EXT["<<i+1<<"]:"<<EXT[i]<<" "<<"MT["<<i+1<<"]:"<<MT[i]<<endl;
    }
    for (int i = 0; i < Q; i++) {
        string FNAME; // One file name per line.
        getline(cin, FNAME);cerr<<"FNAME"<<i+1<<":"<<FNAME<<endl;
        cerr<<"rfind:"<<FNAME.rfind('.')<<endl;
        if(FNAME.rfind('.') <FNAME.length()){
            int a=FNAME.rfind('.') + 1;
            char c[10]="";int b=0;
            for (;a<FNAME.length();b++)
            {
                if(isupper(FNAME[a]))c[b]=FNAME[a] + 32;
                else c[b]=FNAME[a];
                a++;
                }
            cerr<<"c:"<<c<<endl;
            int v=0;
            if(c=="")cout<<"UNKNOWN"<<endl;
            else 
            {   for(;EXT[v]!=c && v<N;v++);
                    if(v<N)cout<<MT[v]<<endl;
                    else cout<<"UNKNOWN"<<endl;
                }
        }
        else cout<<"UNKNOWN"<<endl;
    }
    fclose(stdin);fclose(stdout);fclose(stderr);
        return 0;    
}
为解决问题:https://www.codingame.com/ide/puzzle/mime-type
已经解决,把输入方式改为 scanf 即可
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-1 07:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表