Sicily 1323. Switch text

For study!

Posted by Winray on March 4, 2016
  • 思路:
    • 题目意思不好理解呀。
    • 题目意思是这样的:输入两个测试数据,首先,两个测试数据本身得各自前后倒转,然后两个测试数据倒转后的结果再各自对半互换,然后测试数据二先输出,测试数据一再输出,不断循环下去。还有一点很关键,就是对空行的判断,这个空行可以是空格组成,或者是直接回车,空行是忽略不输出的。还是直接看代码吧,这样好理解一点。用stl会使程序简化明了很多
  • 具体代码如下:
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
    int n, m;
    while (cin >> n && n) {
        cin >> m;
        set<string> v;
        for (int i = 0; i < n; i++) {
            string temp;
            cin >> temp;
            for (int j = 0; j < temp.size(); j++) {  //全部转化为小写 
                temp[j] = tolower(temp[j]);
            }
            v.insert(temp);
        }
        for (int i = 0; i < m; i++) {
            string temp;
            cin >> temp;
            for (int j = 0; j < temp.size(); j++) {
                temp[j] = tolower(temp[j]);
            }
            if (v.count(temp))
                v.erase(temp); 
        }
        cout << v.size() << endl;
    }
    
    return 0;
}