Practice/2017 Computer Science summer camp on-Machine exam: B (String)

Source: Internet
Author: User
Tags lowercase time limit

Source: http://cs101.openjudge.cn/practice/12556/ 12556: encoded string

Total time limit: 1000ms memory limit: 65536kB

Description

In data compression, a common method is the stroke length encoding compression. For a string to be compressed, we can sequentially record each character and the number of repetitions. For example, the string to be compressed is "AAABBBBCBB", and the compression result is (a,3) (b,4) (c,1) (b,2). This compression is effective in cases where the adjacent data is repeated more often, and the compression is less efficient if there are fewer repetitions.

It is now required to first convert all uppercase letters in a string to lowercase letters based on the input string, and then compress the strings.

input

A string with a length greater than 0 and no more than 1000, all of which consist of uppercase or lowercase letters.

Output

The output is the encoded string, in the form: (a,3) (b,4) (c,1) (d,2), which is the lowercase character and the number of repetitions in each pair of parentheses, with no spaces.

Sample Input

Aaabbbbcccaaaaa

Sample Output

(a,3) (b,4) (c,3) (a,5)

-----------------------------------------------------

Thinking of solving problems

Simulation questions

-----------------------------------------------------

Code

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main ()
{
	string s;
	Cin >> S;
	int len = s.length (), i = 0;
	for (i=0; i<len; i++)
	{
		if (s.at (i) >= ' a ' && s.at (i) <= ' Z ')
		{
			s.at (i)-= ' A '-' a ';
		}
	}
	int cnt = 1;
	char c = 0;
	Vector<char> VECC;
	Vector<int> Veci;
	Vecc.push_back (s.at (0));
	for (I=1; i<len; i++)
	{
		if (s.at (i)! = s.at (i-1))
		{
			vecc.push_back (s.at (i));
			Veci.push_back (CNT);
			CNT = 1;
		}
		else
		{
			cnt++;
		}
	}
	Veci.push_back (CNT);
	for (i=0; I<vecc.size (); i++)
	{
		cout << ("<< vecc.at (i) <<", "<< veci.at (i) <&L T ")" ;
	}

}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.