Hash Code Hacker Gym 100801H(很好的一种写法)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值