Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求指教下哪里错了,VS一直显示读取字符串错误,C++写的。

Posted by q544216241 at 2017-01-10 17:22:19 on Problem 1002
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
vector<string> Reflection(string[], int);
int main()
{
	int n;
	string*a = new string[n];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	vector<string> v = Reflection(a, n);
	map<string, int>cnt;
	map<string, int>::iterator cntIT;
	for (int j = 0; j < v.size(); j++)
	{
		if (cnt.find(v[j]) != cnt.end())
		{
			cnt[v[j]]++;
		}
		else
		{
			cnt.insert(pair<string, int>(v[j], 1));
		}
	}
	int p = 0;
	for (cntIT = cnt.begin(); cntIT != cnt.end(); cntIT++)
	{
		if (cntIT->second >= 2)
		{
			cout << cntIT->first << " " << cntIT->second << endl;
		}
		p += cntIT->second;
	}
	if (p == cnt.size())
	{
		cout << "No duplicates.";
	}
	delete[]a;
	return 0;
}

vector<string> Reflection(string a[], int n)
{
	vector<string>vessel;
	for (int i = 0; i < n; i++)
	{
		string s = a[i];
		string newStr="";
		for (int j = 0; j < s.size()-1; j++)
		{
			char c = s[j];
			if (c == '0')
			{
				newStr.push_back('0');
			}
			else if(c == '1')
			{
				newStr.push_back('1');
			}
			else if(c == 'A' || 'B' || 'C' || '2')
			{
				newStr.push_back('2');
			}
			else if(c == 'D' || 'E' || 'F' || '3')
			{
				newStr.push_back('3');
			}
			else if(c == 'G' || 'H' || 'I' || '4')
			{
				newStr.push_back('4');
			}
			else if(c == 'J' || 'K' || 'L' || '5')
			{
				newStr.push_back('5');
			}
			else if(c == 'M' || 'N' || 'O' || '6')
			{
				newStr.push_back('6');
			}
			else if(c == 'P' || 'R' || 'S' || '7')
			{
				newStr.push_back('7');
			}
			else if(c == 'T' || 'U' || 'V' || '8')
			{
				newStr.push_back('8');
			}
			else if(c == 'W' || 'X' || 'Y' || '9')
			{
				newStr.push_back('9');
			}
		}
		newStr.insert(2, "-");
		vessel.push_back(newStr);
	}
	return vessel;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator