鱼C论坛

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

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

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

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

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

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

  5. using namespace std;

  6. /**
  7. * Auto-generated code below aims at helping you parse
  8. * the standard input according to the problem statement.
  9. **/
  10. int main()
  11. {
  12.         freopen("filenamein.txt","r",stdin);
  13.         freopen("filenameout.txt","w",stdout);
  14.         freopen("filenamerr.txt","w",stderr);
  15.     int N; // Number of elements which make up the association table.
  16.     cin >> N; cin.ignore();cerr<<N<<endl;
  17.     int Q; // Number Q of file names to be analyzed.
  18.     cin >> Q; cin.ignore();cerr<<Q<<endl;
  19.     string EXT[10000]; // file extension
  20.     string MT[10000];// MIME type.
  21.     for (int i = 0; i < N; i++) {
  22.         cin >> EXT[i] >> MT[i]; cin.ignore();
  23.         for(int b=0;b<EXT[i].length();b++)
  24.         {
  25.             if(isupper(EXT[i][b]))EXT[i][b]+=32;
  26.             }
  27.         cerr<<"EXT["<<i+1<<"]:"<<EXT[i]<<" "<<"MT["<<i+1<<"]:"<<MT[i]<<endl;
  28.     }
  29.     for (int i = 0; i < Q; i++) {
  30.         string FNAME; // One file name per line.
  31.         getline(cin, FNAME);cerr<<"FNAME"<<i+1<<":"<<FNAME<<endl;
  32.         cerr<<"rfind:"<<FNAME.rfind('.')<<endl;
  33.         if(FNAME.rfind('.') <FNAME.length()){
  34.             int a=FNAME.rfind('.') + 1;
  35.             char c[10]="";int b=0;
  36.             for (;a<FNAME.length();b++)
  37.             {
  38.                 if(isupper(FNAME[a]))c[b]=FNAME[a] + 32;
  39.                 else c[b]=FNAME[a];
  40.                 a++;
  41.                 }
  42.             cerr<<"c:"<<c<<endl;
  43.             int v=0;
  44.             if(c=="")cout<<"UNKNOWN"<<endl;
  45.             else
  46.             {   for(;EXT[v]!=c && v<N;v++);
  47.                     if(v<N)cout<<MT[v]<<endl;
  48.                     else cout<<"UNKNOWN"<<endl;
  49.                 }
  50.         }
  51.         else cout<<"UNKNOWN"<<endl;
  52.     }
  53.     fclose(stdin);fclose(stdout);fclose(stderr);
  54.         return 0;   
  55. }
复制代码

为解决问题:https://www.codingame.com/ide/puzzle/mime-type
已经解决,把输入方式改为 scanf 即可
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-4 06:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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