Delete characters
Description
In this exercise, you will get two strings A and B in each test group and the length of every string is less than 40, you need to delete all characters which are contained in string B from string A.
The character may be space or letter.
Input
first line is a number n(0<n<=50), which stands for the number of test data.
the next 2*n lines contain 2*n strings, and each group of test data contain two strings A and B. There may be space in both A and B.
Output
string A after delete characters, and each output is split by "\n"
if string A is null after delete, you just need to print "\n"
Sample Input
3
WE are family
aeiou
qwert
asdfg
hello world
e l
Sample Output
WE r fmly
qwert
howrd
Hint
the string contains space, so you may need to use fgets() to input a string.
Capital letter and small letter cannot be ignored.
我的
#include<stdio.h>
#include<string.h>
int main() {
int n, jud = 1, i, j;
char a[50], b[50];
scanf("%d", &n);
getchar();//这个不要忘记,不然会错误的
while (n--) {
while (jud) {
fgets(a, 50, stdin);//这里用gets!!!一开始用gets,怎么弄都弄不对,所以用了fgets
fgets(b, 50, stdin);
jud--;
}
jud = 1;
int a1 = strlen(a), b1 = strlen(b);
for (i = 0; i < a1; i++) {
for (j = 0; j < b1; j++) {
if (a[i] == b[j]) {
a[i] = '1';
break;
}
}
}
for (i = 0; i < a1; i++) {
if (a[i] != '1') {
printf("%c", a[i]);
}
}
printf("\n");
}
return 0;
}
标程
1.#include<stdio.h>
2.#include<string.h>
3.
4.#define NUMBER 256
5.
6.void Delete(char *first, char *second) {
7. int i;
8. int hashtable[NUMBER];
9. for (i = 0; i < NUMBER; i++)
10. hashtable[i]=0;
11.
12. char *p = second;
13. while (*p) {
14. hashtable[*p]=1;
15. p++;
16. }
17.
18. char *slow = first;
19. char *fast = first;
20. while (*fast) {
21. if (hashtable[*fast] == 0) {
22. *slow=*fast;
23. slow++;
24. }
25. fast++;
26. }
27. *slow='\0';
28.}
29.
30.int main() {
31. int num;
32. char temp[50];
33. scanf("%d", &num);
34. fgets(temp, 50, stdin);
35. while (num--) {
36. char first[50];
37. char second[50];
38. fgets(first, 50, stdin);
39. fgets(second, 50, stdin);
40. if (first == NULL) {
41. printf("\n");
42. continue;
43. }
44. Delete(first, second);
45. printf("%s\n", first);
46. }
47. return 0;
48.}
①gets——从标准输入接收一串字符,遇到'\n'时结束,但不接收'\n',把 '\n'留存输入缓冲区;把接收的一串字符存储在形式参数指针指向的空间,并在最后自动添加一个'\0'。
getchar——从标准输入接收一个字符返回,多余的字符全部留在输入缓冲区。
fgets——从文件或标准输入接收一串字符,遇到'\n'时结束,把'\n'也作为一个字符接收;把接收的一串字符存储在形式参数指针指向的空间,并在'\n'后再自动添加一个'\0'。
简单说,gets是接收一个不以'\n'结尾的字符串,getchar是接收任何一个字符(包括'\n'),fgets是接收一个以'\n'结尾的字符串。
scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别。
gets可以接收空格
scanf遇到空格、回车和Tab键都会认为输入结束,所有它不能接收空格
fgets用法:
fgets(buf,sizeof(s),stdin):
fgets(buf, n, file) 函数功能:从 目标文件流 file 中读取 n-1 个字符,放入以 buf 起始地址的内存空间中。
楼主的函数调用是这个意思:
首先,s 肯定是一个字符数组。
该调用从 标准输入流 stdin (也就是键盘输入)读入 s 数组的大小(sizeof(s))再减 1 的长度的字符到 buf 所指的内存空间中(前提是buf已经申请好空间了)
在c语言小知识里面有相关资料~~
Delete characters的更多相关文章
- The common Linux Commands
Linux的命令总结 1. man:在线请求系统帮助 例:man mkdir NAME:这个命令的完整全名 mk(make directories) SYNOPSIS:这个命令的基本语法 mkdir ...
- linux commands
abrt-cli --since ;查看abrt捕捉的异常 alias ;别名,alias rm='rm -i':使用“ \rm ” 使用原命令 alsamixer ;图形音量调节,q 增加左声道, ...
- IP-Address TextBox
http://www.codeproject.com/Articles/4693/IP-Address-TextBox 可以下载试用效果.个人感觉功能很强大,但输入时让人不太舒服.可以参考. ntro ...
- tr用法
参考: http://man.linuxde.net/tr shell脚本学习指南 语法 tr [options] source-char-list replace-char-list 用途 转换字符 ...
- jython 2.7 b3发布
Jython 2.7b3 Bugs Fixed - [ 2108 ] Cannot set attribute to instances of AST/PythonTree (blocks pyfla ...
- 初识50个Linux命令
1. [命令]:cat [功能说明]: concatenate files and print on the standard output #连接文件并打印到标准输出,有标准输出的都可以用重定向定向 ...
- linux下的文件操作——批量重命名
概述:在日常工作中,我们经常需要对一批文件进行重命名操作,例如将所有的jpg文件改成bnp,将名字中的1改成one,等等.文本主要为你讲解如何实现这些操作 1.删除所有的 .bak 后缀: renam ...
- 高级I/O之异步I/O
A synchronous I/O operation causes the requesting process to be blocked until that I/O operation com ...
- 在windows下编辑shell脚本注意点
编辑脚本是直接在windows下写的,并没有使用特定的编辑器或者其他工具,所以很有可能出现一些莫名其妙的异常,这些错误是我们眼睛看不到的,遇到这个情况,例如如下异常或者提示语法错误 Java代码 ...
随机推荐
- 学习java第二天
首先我们要知道,java是特分大小写的,基本上分为 类名 我们统一小写 如果是多级的 我们用点来隔开 比如 file.test.number1,类或者接口的话基本上大家都是首字母大写,常量全部大写,然 ...
- SqlDataReader的使用
1.建立数据库连接: 2.设置数据库指令: 3.数据拾取器接收输出的数据: 4.遍历打印数据: using System; using System.Collections.Generic; usin ...
- apache+tomcat分布式集群搭建
今天搭建apche+tomcat分布式集群,遇到很多问题,在网上找到的很多都不成功,然后和同事一起研究了一下,最终搭建成功了.做个笔记,以备自己以后参考. 1,下载apache.在下载Apache(2 ...
- Winform数据导出Execl小工具
前台界面.cs文件 using System; using System.Collections.Generic; using System.ComponentModel; using System. ...
- System.DateTime.Now的内容
?System.DateTime.Now{2016/10/09 15:19:12} Date: {2016/10/09 0:00:00} dateData: 985948826838121 ...
- {matlab}取二值图像centroid几种方法性能比较
试验很简单,取二值图像的质心,三种方法做比较 1.完全采用矩阵性能不做任何循环操作,对find后的值进行除法与取余操作,从而得到centroid 2.完全采用循环操作,最简单明了 3.结合1,2,对每 ...
- Spring3 url匹配规则
Spring3 url匹配规则 Wildcard Description ? 匹配任何单字符 * 匹配0或者任意数量的字符 ** 匹配0或者更多的目录 宝贝网址:
- centos安装mysql5.6的正确姿态
1.准备工作 a)卸载centos默认软件 yum remove mariadb-libs-5.5.35-3.el7.x86_64 b)安装依赖包 yum install -y perl-Module ...
- ASP.NET MVC应用程序执行过程分析
ASP.NET MVC应用程序执行过程分析 2009-08-14 17:57 朱先忠 朱先忠的博客 字号:T | T ASP.NET MVC框架提供了支持Visual Studio的工程模板.本文 ...
- 超链接的那些事(二): 属性href
a标签的属性之一 href 1. 定义 href 属性用于指定超链接目标的 URL. 2. 用法 ①. 锚点 同一页面添加锚点 (1)<a href="#test"& ...