UVA, 10336 Rank the Languages
来源:互联网 发布:虚拟光驱软件免费版 编辑:程序博客网 时间:2024/06/06 04:25
难点在于:递归函数和输出;
#include <iostream>#include <vector>#include <algorithm>#include <map>using namespace std;class Rank{private: int length,width,ans=0; char c; vector <char> v; int a[26][1000]; map <char,int> m; //output char field[1000][1000];public: void Readcase(){ cin>>width>>length; for(int i=0;i<width;i++){ for(int j=0;j<length;j++){ cin>>field[i][j]; } } } void Computing(){ for(int i=0;i<width;i++) for(int j=0;j<length;j++){ vector<char>::iterator it=find(v.begin(),v.end(),field[i][j]); if(it!=v.end()) continue; //找到了 else v.push_back(field[i][j]); } for(int i=0;i<v.size()-1;i++) if(v[i]>v[i+1]) swap(v[i],v[i+1]); for(int k=0;k<v.size();k++){ c=v[k]; for(int i=0;i<width;i++){ for(int j=0;j<length;j++){ if(field[i][j]==c){ dfs(i,j); ans++; } } } m.insert(map<char,int>::value_type(c,ans)); ans=0; } } void Output(){ int l=m.size(),max; map<char,int>::iterator it3; while(l--){ max=m.begin()->second; for(map<char,int>::iterator it2=m.begin();it2!=m.end();it2++){ if(it2->second>max) max=it2->second; } for(it3=m.begin();it3!=m.end();it3++){ if(max==it3->second) break; } cout<<it3->first<<": "<<it3->second<<endl; m.erase(it3); } } void dfs(int x,int y){ field[x][y]='*'; //标记这个地方已经找过了 if(0<=x&&x<width&&0<=y&&(y-1)<length&&field[x][y-1]==c){ dfs(x,y-1); } if(0<=x&&x<width&&0<=y&&(y+1)<length&&field[x][y+1]==c){ dfs(x,y+1); } if(0<=(x+1)&&(x+1)<width&&0<=y&&y<length&&field[x+1][y]==c){ dfs(x+1,y); } if(0<=(x-1)&&(x-1)<width&&0<=y&&y<length&&field[x-1][y]==c){ dfs(x-1,y); } }};int main(){ int cases; cin>>cases; for(int i=1;i<=cases;i++){ Rank r; r.Readcase(); r.Computing(); cout<<"World #"<<i<<endl; r.Output(); } return 0;}
0 0
- UVa 10336 - Rank the Languages
- Uva 10336 Rank the Languages
- UVA 10336 Rank the Languages
- UVA, 10336 Rank the Languages
- UVA 10336 Rank the Languages
- dfs-Rank the Languages
- UVA10336 Rank the Languages(DFS)
- The Programming Languages Beacon
- The Programming Languages Beacon
- Uva 10887 Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- uva 10887 - Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- UVA 10887 Concatenation of Languages
- uva 10887 - Concatenation of Languages
- uva 10887 - Concatenation of Languages
- UVA 10887 Concatenation of Languages
- UVa:10887 Concatenation of Languages
- Java笔记 - 多线程的安全问题
- apache mina2 用户指南(十五)代理
- Java网络编程(三) UDP通信
- 滴滴出行 2017 软件开发 面试
- nginx+tomcat+memcache----3 memcache
- UVA, 10336 Rank the Languages
- [LeetCode]--8. String to Integer (atoi)
- 计算 TPS,QPS
- 第一期资料
- Min Max Roads(树剖+线段树)
- C# Winform控件贴透明png图片遇到的问题
- Apache mina2 用户指南(十四)状态机
- C语言(10)------逻辑运算符
- Java Output Formatting