Easy Solution in c++
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    \n    vector<string> generateSwappedNumbers(string numstr) {\n        vector<string> swappedNumbers;\n       
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    \n    vector<string> generateSwappedNumbers(string numstr) {\n        vector<string> swappedNumbers;\n        int n = numstr.size();\n        swappedNumbers.push_back(numstr); \n        \n        if (n == 1) {\n            return swappedNumbers;\n        }\n        \n      \n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                swap(numstr[i], numstr[j]);\n                swappedNumbers.push_back(numstr);\n                \n                \n                for (int k = 0; k < n; k++) {\n                    for (int l = k + 1; l < n; l++) {\n                        swap(numstr[k], numstr[l]);\n                        swappedNumbers.push_back(numstr);\n                        swap(numstr[k], numstr[l]);\n                    }\n                }\n                \n                swap(numstr[i], numstr[j]); \n            }\n        }\n        \n        return swappedNumbers;\n    }\n\n    int countPairs(vector<int>& nums) {\n        int n = nums.size();\n        int count = 0;\n        unordered_map<int, int> seen;\n        sort(nums.begin(), nums.end());\n        for (int i = 0; i < n; i++) {\n            string numstr = to_string(nums[i]);\n            vector<string> swappedNumbers = generateSwappedNumbers(numstr);\n            \n            \n            unordered_map<int, bool> checked; \n            for (const string& s : swappedNumbers) {\n                int swappedNum = stoi(s);\n                if (seen.count(swappedNum) && !checked[swappedNum]) {\n                    count += seen[swappedNum];\n                    checked[swappedNum] = true;  \n                }\n            }\n            \n           \n            seen[stoi(numstr)]++;\n        }\n\n        return count;\n    }\n};\n\n```
['C++']