Concatenation (很好的思维题)

Problem C. Concatenation
Input file: concatenation.in
Output file: concatenation.out
Time limit: 2 seconds
Memory limit: 256 megabytes
Famous programmer Gennady likes to create new words. One way to do it is to concatenate existing
words. That means writing one word after another. For example, if he has words “cat” and “dog”, he
would get a word “catdog”, that could mean something like the name of a creature with two heads: one
cat head and one dog head.
Gennady is a bit bored of this way of creating new words, so he has invented another method. He takes
a non-empty prefix of the first word, a non-empty suffix of the second word, and concatenates them. For
example, if he has words “tree” and “heap”, he can get such words as “treap”, “tap”, or “theap”. Who
knows what they could mean?
Gennady chooses two words and wants to know how many different words he can create using his new
method. Of course, being a famous programmer, he has already calculated the answer. Can you do the
same?
Input
Two lines of the input file contain words chosen by Gennady. They have lengths between 1 and 100 000
characters and consist of lowercase English letters only.
Output
Output one integer — the number of different words Gennady can create out of words given in the input
file.
Examples
concatenation.in concatenation.out
cat
dog
9
tree
heap
14

题意:让数组a和数组b的长度相乘然后减去a中a和b想同的字母的个数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll aa, bb, res, i;
char a[100005],b[100005];
int sum[200];
int main()
{
    scanf("%s",a);
    scanf("%s",b);
    aa = strlen(a);
    bb = strlen(b);
    memset(sum,0,sizeof(sum));
    res = aa * bb;
    for(i = 1; i < aa ; i++)
        ++sum[a[i]];
    for(i = 0 ; i < bb - 1; i++)
        res -= sum[b[i]];
    printf("%lld\n",res);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值