杭电acm 1028题,我在自己编译器上一直没问题,提交上去却一直wrong answer,请大伙指点下我,不胜感激!
#include<iostream>#include<cstdio>#include<string>#include<vector>usingnamespacestd;i...
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
int main()
{
int N;
while(scanf("%d", &N) != EOF)
{
while(N--)
{
string str;
vector<char> vect;
int cont = 1;
cin >> str;
unsigned int len = static_cast<unsigned int> (str.size());
for(int i = 1; i < len; i++)
{
if(str.at(i) == str.at(i-1))
{
cont++;
if(i == len-1)
{
char cnt = cont + '0';
vect.push_back(cnt);
vect.push_back(str.at(i));
cont = 1;
}
}
else
{
if(1 != cont)
{
char cnt = cont + '0';
vect.push_back(cnt);
vect.push_back(str.at(i-1));
cont = 1;
}
else if(i == len-1)
{
vect.push_back(str.at(i-1));
vect.push_back(str.at(i));
}
else
vect.push_back(str.at(i-1));
}
}
for(vector<char>::iterator iter = vect.begin(); iter != vect.end(); iter++)
{
cout << *iter;
}
cout << endl;
}
}
return 0;
} 展开
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
int main()
{
int N;
while(scanf("%d", &N) != EOF)
{
while(N--)
{
string str;
vector<char> vect;
int cont = 1;
cin >> str;
unsigned int len = static_cast<unsigned int> (str.size());
for(int i = 1; i < len; i++)
{
if(str.at(i) == str.at(i-1))
{
cont++;
if(i == len-1)
{
char cnt = cont + '0';
vect.push_back(cnt);
vect.push_back(str.at(i));
cont = 1;
}
}
else
{
if(1 != cont)
{
char cnt = cont + '0';
vect.push_back(cnt);
vect.push_back(str.at(i-1));
cont = 1;
}
else if(i == len-1)
{
vect.push_back(str.at(i-1));
vect.push_back(str.at(i));
}
else
vect.push_back(str.at(i-1));
}
}
for(vector<char>::iterator iter = vect.begin(); iter != vect.end(); iter++)
{
cout << *iter;
}
cout << endl;
}
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询