Problem Info
Name of problem:
Cities and States
My Work
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int main()
{
ifstream fin(“citystate.in”);
ofstream fout(“citystate.out”);
unordered_map<string, set<int>> cityState;
int N;
fin >> N;
for (int i = 0; i < N; ++i)
{
string a, b;
fin >> a >> b;
char a1 = a[0];
char a2 = a[1];
char b1 = b[0];
char b2 = b[1];
string s;
s.push_back(a1);
s.push_back(a2);
s.push_back(b1);
s.push_back(b2);
cityState[s].insert(i);
}
int twoAns = 0;
for (const auto& it : cityState)
{
string s;
s.push_back(it.first[2]);
s.push_back(it.first[3]);
s.push_back(it.first[0]);
s.push_back(it.first[1]);
for (int element : it.second)
{
twoAns += cityState[s].size() - cityState[s].count(element);
}
}
int ans = twoAns / 2;
fout << ans;
}
cpp
Add commented code here
Add explanation of code here
## What I've Tried
I've ran it in tests, and it always outputted the right answer in Visual Studio, it's a completely different story when I try to submit this. WHY???????????????????????? Why does it output one thing in Visual Studio but something different in submission? I even decided to use the cout function and the fout function, yet it's always the same thing: 1. When I submit this, it's 0. This has never happened to me before.
## Question
Include a specific question if you have one.
## Checklist
See [How to ask for help on a problem](https://forum.usaco.guide/t/how-to-ask-for-help-on-a-problem/338/2) for more information.
- Include a link to the problem
- Format your post (especially code blocks)
- Include what you've tried so far
- Add comments to your code
- Read the [debugging module](https://usaco.guide/general/debugging-general)