浏览代码

Klar med 10260 och 465

Jonatan Gezelius 6 年之前
父节点
当前提交
d020c04b86
共有 3 个文件被更改,包括 114 次插入0 次删除
  1. 13 0
      mall/pxxxx.cpp
  2. 54 0
      p10260/p10260.cpp
  3. 47 0
      p465/p465.cpp

+ 13 - 0
mall/pxxxx.cpp

@@ -0,0 +1,13 @@
+#include <algorithm>
+#include <array>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <vector>
+
+using namespace std;
+
+int main()
+{
+    return 0;
+}

+ 54 - 0
p10260/p10260.cpp

@@ -0,0 +1,54 @@
+#include <iostream>
+#include <string>
+#include <map>
+
+using namespace std;
+
+int main()
+{
+    map<char, int> soundex;
+    string word;
+
+    soundex['B'] = 1;
+    soundex['F'] = 1;
+    soundex['P'] = 1;
+    soundex['V'] = 1;
+    soundex['C'] = 2;
+    soundex['G'] = 2;
+    soundex['J'] = 2;
+    soundex['K'] = 2;
+    soundex['Q'] = 2;
+    soundex['S'] = 2;
+    soundex['X'] = 2;
+    soundex['Z'] = 2;
+    soundex['D'] = 3;
+    soundex['T'] = 3;
+    soundex['L'] = 4;
+    soundex['M'] = 5;
+    soundex['N'] = 5;
+    soundex['R'] = 6;
+
+    while(cin >> word)
+    {
+        char last = 0;
+
+        for(char c : word)
+        {
+            if(soundex.find(c) != soundex.end())
+            {
+                if(last != soundex[c])
+                {
+                    cout << soundex[c];
+                }
+                last = soundex[c];
+            }
+            else
+            {
+                last = 0;
+            }
+        }
+        cout << endl;
+    }
+
+    return 0;
+}

+ 47 - 0
p465/p465.cpp

@@ -0,0 +1,47 @@
+#include <algorithm>
+#include <array>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <vector>
+#include <iomanip>
+#include <sstream>
+#include <climits>
+
+using namespace std;
+
+int main()
+{
+    double left, right, result;
+    string left_s, right_s;
+
+    char operation;
+    while(cin >> left_s >> operation >> right_s)
+    {
+        cout << left_s << " " << operation << " " << right_s << endl;
+        stringstream ss;
+        ss << left_s << " " << right_s;
+        ss >> left >> right;
+
+        if(left > INT_MAX)
+        {
+            cout << "first number too big" << endl;
+        }
+        if(right > INT_MAX)
+        {
+            cout << "second number too big" << endl;
+        }
+
+        if(operation == '+')
+            result = left + right;
+        else
+            result = left * right;
+
+        if(result > INT_MAX)
+        {
+            cout << "result too big" << endl;
+        }
+    }
+
+    return 0;
+}