{"id":"88c1bfd0-d695-4c9c-a1f9-f47448d4f5a8","name":"Subdomain Visit Count","description":"1. A website domain like \"www.pepcoding.com\" consists of various subdomains like \r\n \"com\" at the topmost level, \"pepcoding.com\" at the next level, and \"www.pepcoding.com\" at the lowest level.\r\n2. When you visit a domain like \"www.pepcoding.com\", you will also visit its parent domains \"pepcoding.com\" and \"com\". \r\n3. You are given N number of strings where every string contains a number and a domain separated by a space, where the number represents the visit count of the domain.\r\n4. You have to find the number of visits for each sub-domain.","inputFormat":"A number N\r\nN strings. Each string contains a number and domain.","outputFormat":"Every line of output contains a number and a sub-domain, where the number represents the visit count of the sub-domain.","constraints":"1 &lt;= N &lt;= 100\r\n1 &lt;= visit count of a domain &lt;= 10^4\r\n1 &lt;= length of domain name &lt;= 100\r\nEach address will contain at most 2 \".\" characters.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n#include <iomanip>\nusing namespace std;\n\nvector<string> subdomainVisits(vector<string>& cpdomains)\n{\n //write your code here\n}\n\n\nint main() {\n\n\n string n;\n cin >> n;\n\n vector<string>arr;\n for (int i = 0; i < stoi(n); i++) {\n string s;\n getline(cin >> ws, s);\n arr.push_back(s);\n }\n vector<string> ans = subdomainVisits(arr);\n sort(ans.begin(), ans.end());\n for (string str : ans) {\n cout << str << endl;\n }\n\n\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n\tpublic static List<String> subdomainVisits(String[] cpdomains) {\r\n\t\t// write your code here\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\tint n = Integer.parseInt(s.nextLine());\r\n\t\tString[] cpd = new String[n];\r\n\t\tfor (int i = 0; i < cpd.length; i++) {\r\n\t\t\tcpd[i] = s.nextLine();\r\n\t\t}\r\n\t\tList<String> ans = subdomainVisits(cpd);\r\n\t\tCollections.sort(ans);\r\n\t\tSystem.out.println(ans);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1\r\n9999 www.pepcoding.com","sampleOutput":"9999 com\r\n9999 pepcoding.com\r\n9999 www.pepcoding.com\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"99af7022-176e-4979-a9dc-360f977c0b9d","name":"Subdomain Visit Count","slug":"subdomain-visit-count","type":1}],"next":{"id":"5a4a4efd-3b55-4bf6-996a-87151d0478e9","name":"Subdomain Visit Count MCQ","type":0,"slug":"subdomain-visit-count-mcq"},"prev":{"id":"8c10ae57-8db2-42fb-b76d-5a8be78942c7","name":"Powerful Number","type":3,"slug":"powerful-number"}}}

Subdomain Visit Count

1. A website domain like "www.pepcoding.com" consists of various subdomains like "com" at the topmost level, "pepcoding.com" at the next level, and "www.pepcoding.com" at the lowest level. 2. When you visit a domain like "www.pepcoding.com", you will also visit its parent domains "pepcoding.com" and "com". 3. You are given N number of strings where every string contains a number and a domain separated by a space, where the number represents the visit count of the domain. 4. You have to find the number of visits for each sub-domain.

{"id":"88c1bfd0-d695-4c9c-a1f9-f47448d4f5a8","name":"Subdomain Visit Count","description":"1. A website domain like \"www.pepcoding.com\" consists of various subdomains like \r\n \"com\" at the topmost level, \"pepcoding.com\" at the next level, and \"www.pepcoding.com\" at the lowest level.\r\n2. When you visit a domain like \"www.pepcoding.com\", you will also visit its parent domains \"pepcoding.com\" and \"com\". \r\n3. You are given N number of strings where every string contains a number and a domain separated by a space, where the number represents the visit count of the domain.\r\n4. You have to find the number of visits for each sub-domain.","inputFormat":"A number N\r\nN strings. Each string contains a number and domain.","outputFormat":"Every line of output contains a number and a sub-domain, where the number represents the visit count of the sub-domain.","constraints":"1 &lt;= N &lt;= 100\r\n1 &lt;= visit count of a domain &lt;= 10^4\r\n1 &lt;= length of domain name &lt;= 100\r\nEach address will contain at most 2 \".\" characters.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n#include <iomanip>\nusing namespace std;\n\nvector<string> subdomainVisits(vector<string>& cpdomains)\n{\n //write your code here\n}\n\n\nint main() {\n\n\n string n;\n cin >> n;\n\n vector<string>arr;\n for (int i = 0; i < stoi(n); i++) {\n string s;\n getline(cin >> ws, s);\n arr.push_back(s);\n }\n vector<string> ans = subdomainVisits(arr);\n sort(ans.begin(), ans.end());\n for (string str : ans) {\n cout << str << endl;\n }\n\n\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n\tpublic static List<String> subdomainVisits(String[] cpdomains) {\r\n\t\t// write your code here\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\tint n = Integer.parseInt(s.nextLine());\r\n\t\tString[] cpd = new String[n];\r\n\t\tfor (int i = 0; i < cpd.length; i++) {\r\n\t\t\tcpd[i] = s.nextLine();\r\n\t\t}\r\n\t\tList<String> ans = subdomainVisits(cpd);\r\n\t\tCollections.sort(ans);\r\n\t\tSystem.out.println(ans);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1\r\n9999 www.pepcoding.com","sampleOutput":"9999 com\r\n9999 pepcoding.com\r\n9999 www.pepcoding.com\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"99af7022-176e-4979-a9dc-360f977c0b9d","name":"Subdomain Visit Count","slug":"subdomain-visit-count","type":1}],"next":{"id":"5a4a4efd-3b55-4bf6-996a-87151d0478e9","name":"Subdomain Visit Count MCQ","type":0,"slug":"subdomain-visit-count-mcq"},"prev":{"id":"8c10ae57-8db2-42fb-b76d-5a8be78942c7","name":"Powerful Number","type":3,"slug":"powerful-number"}}}
plane

Editor


Loading...

Subdomain Visit Count

medium

1. A website domain like "www.pepcoding.com" consists of various subdomains like "com" at the topmost level, "pepcoding.com" at the next level, and "www.pepcoding.com" at the lowest level. 2. When you visit a domain like "www.pepcoding.com", you will also visit its parent domains "pepcoding.com" and "com". 3. You are given N number of strings where every string contains a number and a domain separated by a space, where the number represents the visit count of the domain. 4. You have to find the number of visits for each sub-domain.

Constraints

1 <= N <= 100 1 <= visit count of a domain <= 10^4 1 <= length of domain name <= 100 Each address will contain at most 2 "." characters.

Format

Input

A number N N strings. Each string contains a number and domain.

Output

Every line of output contains a number and a sub-domain, where the number represents the visit count of the sub-domain.

Example

Sample Input

1 9999 www.pepcoding.com

Sample Output

9999 com 9999 pepcoding.com 9999 www.pepcoding.com

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode