1050 String Subtraction (20 分)C语言

1050 String Subtraction (20 分)

Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking all the characters in S​2​​ from S​1​​. Your task is simply to calculate S​1​​−S​2​​ for any given strings. However, it might not be that simple to do it fast.

Input Specification:

Each input file contains one test case. Each case consists of two lines which gives S​1​​ and S​2​​, respectively. The string lengths of both strings are no more than 10​4​​. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

Output Specification:

For each test case, print S​1​​−S​2​​ in one line.

Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.

分析

1 gets(str)输入,注意输入结束后,会在输入的字符串后面加个'\0'

char str[]="123456";gets(str);         abc↙            str会变成abc\056

char str2[19];gets(str2);       abc 12d3\n 456\0 efg↙      str变成"abc 12d3\n 456\0 789"//gets()以回车为结束符,\n、\0、空格对它没影响

而scanf(“%s”,str2);  遇到空格就会结束

2 考虑到根据s2循环遍历s1,有点麻烦,肯能又要运行超时,做了一个ASCII数组

代码

#include<stdio.h>
#define MAX 11000
int ASCII[300]={0};
int main(){
    int i;
    char s1[MAX],s2[MAX];
    gets(s1);gets(s2);//can't use scanf() for it's string end with white space
    //just gets(string) end with enter not space
    for(i=0;i<strlen(s2);i++) ASCII[ s2[i] ] =1;
    for(i=0;i<strlen(s1);i++)  if( !ASCII[ s1[i] ] ) printf("%c",s1[i]);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
没问题,我可以帮您回答这个问题。以下是一些 C 语言语音帧、加窗和降噪的例子: 1. 语音帧 ``` // 假设采样率为 16000Hz,帧长为 20ms(320个采样点) short signal[N]; // N 为语音信号长度 int framesize = 320; // 帧长 int framestep = 160; // 帧移 int numframes = 1 + (int)((N - framesize) / framestep); // 帧数 float** frames = (float**)calloc(numframes, sizeof(float*)); for (int i = 0; i < numframes; i++) { frames[i] = (float*)calloc(framesize, sizeof(float)); for (int j = 0; j < framesize; j++) { frames[i][j] = signal[i*framestep+j] / 32768.0f; } } ``` 2. 加窗 ``` // 假设使用的是汉明窗 for (int i = 0; i < numframes; i++) { for (int j = 0; j < framesize; j++) { frames[i][j] *= 0.54f - 0.46f*cos(2*M_PI*j/(framesize-1)); } } ``` 3. 降噪 ``` // 假设使用的是 Spectral Subtraction 算法 // 先计算所有帧的能量 float* frame_energy = (float*)calloc(numframes, sizeof(float)); for (int i = 0; i < numframes; i++) { for (int j = 0; j < framesize; j++) { frame_energy[i] += frames[i][j] * frames[i][j]; } } // 计算噪声能量 int numnoise = 10; // 选择前 10 帧作为噪声参考 float noise_energy = 0; for (int i = 0; i < numnoise; i++) { noise_energy += frame_energy[i]; } noise_energy /= numnoise; // 计算每一帧的噪声能量 float* noise_threshold = (float*)calloc(numframes, sizeof(float)); for (int i = 0; i < numframes; i++) { noise_threshold[i] = noise_energy * 1.5f; } // 对每一帧做减噪处理 for (int i = 0; i < numframes; i++) { float frame_max = 0; for (int j = 0; j < framesize; j++) { if (frames[i][j] > frame_max) { frame_max = frames[i][j]; } } float alpha = 0.1f; // 调整 alpha 的值可以控制噪声抑制的程度 float beta = 1.0f - alpha; float noise_floor = beta * noise_threshold[i] + alpha * frame_max; for (int j = 0; j < framesize; j++) { if (frames[i][j] < noise_floor) { frames[i][j] = 0; } } } ``` 希望这些例子可以帮助您实现语音帧、加窗和降噪。如果您有更多的问题,欢迎继续向我提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值