programming-challenges Crypt Kicker II (110304) 题解
2015-06-22 12:02
483 查看
注意错误是输出是:"No solution.",后面有point的
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <assert.h> #include <algorithm> #include <math.h> #include <ctime> #include <functional> #include <string.h> #include <stdio.h> #include <numeric> #include <float.h> using namespace std; vector<string> parseString(string &s) { vector<string> subStrs; string ts; for (int i = 0; i < s.size(); i++) { if (s[i] != ' ') { ts.push_back(s[i]); } else { if (!ts.empty()) subStrs.push_back(ts); ts.clear(); } } if (!ts.empty()) subStrs.push_back(ts); return subStrs; } int main() { string orig = "the quick brown fox jumps over the lazy dog"; vector<string> origSubStrs = parseString(orig); int TC = 0; cin >> TC; cin.get(); cin.get(); bool blank = false; for (int tc = 1; tc <= TC; tc++) { string s; vector<string> lines; if (tc > 1) cin.get(); while (true) { if (cin.peek() == '\n' || cin.eof()) break; getline(cin, s); lines.push_back(s); } if (blank) { cout << endl; } blank = true; bool ok = false; for (int i = 0; i < lines.size(); i++) { int sourceToObj[26], objToSource[26]; for (int j = 0; j < 26; j++) { sourceToObj[j] = objToSource[j] = -1; } vector<string> tSubStrs = parseString(lines[i]); if (tSubStrs.size() != origSubStrs.size()) continue; ok = true; for (int j = 0; j < tSubStrs.size() && ok; j++) { if (tSubStrs[j].size() != origSubStrs[j].size()) { ok = false; } else { for (int k = 0; k < tSubStrs[j].size() && ok; k++) { int i1 = tSubStrs[j][k] - 'a'; int i2 = origSubStrs[j][k] - 'a'; if (sourceToObj[i2] != -1 && sourceToObj[i2] != i1) { ok = false; } else if (objToSource[i1] != -1 && objToSource[i1] != i2) { ok = false; } else { sourceToObj[i2] = i1; objToSource[i1] = i2; } } } } if (ok) { // output answer for (int j = 0; j < lines.size(); j++) { for (int k = 0; k < lines[j].size(); k++) { if (lines[j][k] == ' ') cout << ' '; else cout << (char)('a' + objToSource[lines[j][k] - 'a']); } cout << endl; } break; } } if (!ok) { cout << "No solution." << endl; } } return 0; }
相关文章推荐
- ./configure详解
- 使用Google Elevation API获取海拔高度(java版)
- some useful websites
- Hibernate的缓存(收集)
- grails调用存储过程(调用的时候call不能少了那个一对大括号{},少了调用结果不对)
- poj3311 Hie with the Pie
- 读取图像鼠标位置处坐标和BGR
- C语言(2)数据类型、常量、Printf、sizeof、scanf的使用
- C++函数模板
- 磁盘UUID以及卷标
- C++类构造函数初始化列表,子类向父类传参数
- Xcode下 写c代码
- SQL truncate 、delete与drop区别(转)
- grails不想用系统生成的字段id可以自己改
- CentOS 6.6 LVM添加2T硬盘
- 北京络捷斯特物流系统(四)
- c++ 子类调用父类有参构造函数
- Grails验证与错误打印
- 2015年06开始学习Java
- 在Grails中如何使用Class.forName