|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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 即可 |
|