首页 > ACM题库 > HDU-杭电 > hdu 2573 Typing-动态规划-[解题报告]C++
2014
02-10

hdu 2573 Typing-动态规划-[解题报告]C++

Typing

问题描述 :

A boy named Pirates who wants to develop typing software finds that it’s hard to judge whether a letter is lowercase or uppercase. He searches lots of information about it, and find out the solution, but he doesn’t know how to realize it. Can you help him?
  
The Solution:
1: If the caps lock is on, and the letter is typed with shift key down, the letter is lowercase, otherwise it’s uppercase.
2: If the caps lock is off, and the letter is typed with shift key down, the letter is uppercase, otherwise it’s lowercases.

输入:

  The first line is an integer t, which is the number of test case in the input data file. Each test case begins with an integer n (0<n<=100), which means there follow n lines. For each line, if there is only a letter, it means the key is typed, and if there begins with a string “Shift”, then will follows one letter, it means the letter is typed with shift key, and if there begins with a string “Caps”, it means the caps lock key is typed and changes the mood of caps lock. The entire letter is lowercase. At the beginning of each test case, you can assume that the caps lock is off.

输出:

  The first line is an integer t, which is the number of test case in the input data file. Each test case begins with an integer n (0<n<=100), which means there follow n lines. For each line, if there is only a letter, it means the key is typed, and if there begins with a string “Shift”, then will follows one letter, it means the letter is typed with shift key, and if there begins with a string “Caps”, it means the caps lock key is typed and changes the mood of caps lock. The entire letter is lowercase. At the beginning of each test case, you can assume that the caps lock is off.

样例输入:

2
5
Caps
a
c
Shift i
Shift t
6
Caps
a
c
Caps
i
t

样例输出:

ACit
ACit

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int t; 
	cin >> t;
	while(t--)
	{
		int n;
		int flag = 0;
		char a[10];
		cin >> n;
		while(n--)
		{
			cin >> a;
			if(strcmp("Caps", a) == 0)
			{
				if(flag == 0)
					flag = 1;
				else
					flag = 0;
				continue;
			}
			if(strcmp("Shift", a) == 0)
			{
				cin >> a;
				if(flag == 1)
					putchar(tolower(a[0]));
				else
					putchar(toupper(a[0]));
				continue;
			}
			if(flag == 0)
				putchar( tolower(a[0]));
			else if(flag == 1)
				putchar( toupper(a[0]));
		}
		cout << endl;
	}
	return 0;
}

解题转自:http://blog.csdn.net/vsooda/article/details/7985320


  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  2. 在方法1里面:

    //遍历所有的边,计算入度
    for(int i=0; i<V; i++)
    {
    degree = 0;
    for (j = adj .begin(); j != adj .end(); ++j)
    {
    degree[*j]++;
    }
    }

    为什么每遍历一条链表,要首先将每个链表头的顶点的入度置为0呢?
    比如顶点5,若在顶点1、2、3、4的链表中出现过顶点5,那么要增加顶点5的入度,但是在遍历顶点5的链表时,又将顶点5的入度置为0了,那之前的从顶点1234到顶点5的边不是都没了吗?