处理 SSI 文件时出错
lower's blog 'S bLog
 
 

Hnu lower's blog

Welcome!

<<  < 2007 - >  >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
 
处理 SSI 文件时出错
 
Topcoder SRM 145 250 points
[ 2007-4-18 20:29:00 | By: lower ]
 
感觉Tc的题目用来练习C++还是不错的。
Problem Statement
    
Sometimes when computer programs have a limited number of colors to use, they use a technique called
dithering. Dithering is when you use a pattern made up of different colors such that when the colors
are viewed together, they appear like another color. For example, you can use a checkerboard pattern
of black and white pixels to achieve the illusion of gray.
You are writing a program to determine how much of the screen is covered by a certain dithered color.
Given a computer screen where each pixel has a certain color, and a list of all the solid colors that
make up the dithered color, return the number of pixels on the screen that are used to make up the
dithered color. Each pixel will be represented by a character in screen. Each character in screen and
in dithered will be an uppercase letter ('A'-'Z') representing a color.
Assume that any pixel which is a color contained in dithered is part of the dithered color.
Definition
    
Class:
ImageDithering
Method:
count
Parameters:
string, vector <string>
Returns:
int
Method signature:
int count(string dithered, vector <string> screen)
(be sure your method is public)
    
Constraints
-
dithered will contain between 2 and 26 upper case letters ('A'-'Z'), inclusive.
-
There will be no repeated characters in dithered.
-
screen will have between 1 and 50 elements, inclusive.
-
Each element of screen will contain between 1 and 50 upper case letters ('A'-'Z'), inclusive.
-
All elements of screen will contain the same number of characters.
Examples
0)
  
"BW"
{"AAAAAAAA",
 "ABWBWBWA",
 "AWBWBWBA",
 "ABWBWBWA",
 "AWBWBWBA",
 "AAAAAAAA"}
Returns: 24



#i nclude <iostream>
#i nclude <string>
#i nclude <vector>
using namespace std;
class ImageDithering
{
      public:
             int count(string dithered, vector<string> screen);
};
int ImageDithering::count(string dithered, vector<string> screen)
{
    int i,a[26],res;
    memset(a,0,sizeof(a));
    for (i=0; i<dithered.size(); ++i)
        a[dithered[i]-'A']++;
    vector<string>::iterator ster1=screen.begin();
    res=0;
    for ( ; ster1!=screen.end(); ++ster1)
    {
        for (i=0; i<(*ster1).size(); ++i)
        {
            if (a[(*ster1)[i]-'A'])
               res++;
        }
    }
    return res;
}
int main()
{
    string dithere,tmp;
    vector<string> screen;
    ImageDithering a;
    cin >> dithere;
    while (cin >> tmp)
          screen.push_back(tmp);
    cout << a.count(dithere,screen)<< endl;
    system("pause");
    return 0;
}
 
 
处理 SSI 文件时出错

发表评论:

    大名:
    密码: (游客无须输入密码)
    主页:
    标题:
    教育人博客页面数据载入,请耐心等待
 
 
 
处理 SSI 文件时出错