Problem H. Hash Code Hacker
Input file: hash.in
Output file: hash.out
Time limit: 2 seconds
Memory limit: 256 megabytes
According to Java standard library documentation, the hash code of String is computed as
s [0]*31^( n -1) + s [1]*31^( n -2) + … + s [n -1]
Here s[i] is the i-th character of the string, n is the length of the string, and ^ indicates exponentiation.
Computation uses signed 32-bit integers in two’s complement form.
Heather is going to hack the servers of Not Entirely Evil Recording Company (NEERC). To perform
an attack she needs k distinct query strings that have equal hash codes. Unfortunately, NEERC servers
accept query string containing lower- and uppercase English letters only.
Heather hired you to write a program that generates such query strings for her.
Input
The single line of the input file contains integer k — the number of required query strings to generate
(2 ≤ k ≤ 1000).
Output
Output k lines. Each line should contain a single query string. Each query string should be non-empty
and its length should not exceed 1000 characters. Query string should contain only lower- and uppercase
English letters. All query strings should be distinct and should have equal hash codes.
Example
hash.in hash.out
4 edHs
mENAGeS
fEHs
edIT
看作是三十一进制
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
using namespace std;
#define ll long long
#pragma comment(linker,"/STACk:10240000,10240000")
const int maxn=1e3+10;
char str[maxn];
int main()
{
freopen("hash.in","r",stdin);
freopen("hash.out","w",stdout);
int k;
scanf("%d",&k);
for(int i=0;i<1000;i++) str[i]='X';
puts(str);
for(int i=0;i<k-1;i++)
{
str[i]-=1;str[i+1]+=31;
puts(str);
str[i]+=1,str[i+1]-=31;
}
return 0;
}