版本1和4间的区别 (跳过第3版)
于2006-03-11 16:50:36修订的的版本1
大小: 811
编辑: czk
备注:
于2006-04-23 22:35:25修订的的版本4
大小: 1531
编辑: 153
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 1: 行号 1:
## page was renamed from 程序设计练习27——zju2478——Encoding
行号 2: 行号 3:
Time limit: 1 Seconds    Time limit: 1 Seconds
行号 4: 行号 5:
Memory limit: 32768K   Memory limit: 32768K
行号 10: 行号 11:

行号 13: 行号 12:

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 100.
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 100.
行号 18: 行号 15:
行号 27: 行号 23:
行号 34: 行号 29:
行号 35: 行号 31:
{{{#!cplusplus
/*written by 洪峰 but wa now*/

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

int main()
{
 char com[26];
 int i,j,k,n;
 string s;
 vector<int> res(26,0),data(26,0);
 for (i=0;i<26;i++)
  com[i]=65+i;
 cin>>n;
 for (i=0;i<n;i++)
 {
  if (n<1||n>100)
   exit(0);
  cin>>s;
  for (j=0;j<s.length();j++)
   for (k=0;k<26;k++)
    if (s[j]==com[k])
     res[k]++;
  for (j=0;j<26;j++)
   if (res[j]==1)
    cout<<com[j];
   else if (res[j]==0)
    continue;
   else
    cout<<res[j]<<com[j];
  if (i+1<n)
   cout<<endl;
  s.clear();
  res=data;
 }
 system("pause");
 return 0;
}
}}}

Encoding

Time limit: 1 Seconds

Memory limit: 32768K

Given a string containing only 'A' - 'Z', we could encode it using the following method:

  1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
  2. If the length of the sub-string is 1, '1' should be ignored.

1. Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 100.

2. Output

For each test case, output the encoded string in a line.

3. Sample Input

2
ABC
ABBCCC

4. Sample Output

ABC
A2B3C

http://acm.zju.edu.cn/show_problem.php?pid=2478


   1 /*written by 洪峰 but wa now*/
   2 
   3 #include<iostream>
   4 #include<vector>
   5 #include<string>
   6 using namespace std;
   7 
   8 int main()
   9 {
  10  char com[26];
  11  int i,j,k,n;
  12  string s;
  13  vector<int> res(26,0),data(26,0);
  14  for (i=0;i<26;i++)
  15   com[i]=65+i;
  16  cin>>n;
  17  for (i=0;i<n;i++)
  18  {
  19   if (n<1||n>100)
  20    exit(0);
  21   cin>>s;
  22   for (j=0;j<s.length();j++)
  23    for (k=0;k<26;k++)
  24     if (s[j]==com[k])
  25      res[k]++;
  26   for (j=0;j<26;j++)
  27    if (res[j]==1)
  28     cout<<com[j];
  29    else if (res[j]==0)
  30     continue;
  31    else
  32     cout<<res[j]<<com[j];
  33   if (i+1<n)
  34    cout<<endl;
  35   s.clear();
  36   res=data;
  37  }
  38  system("pause");
  39  return 0;
  40 }

zju2478 (2008-02-23 15:34:13由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.