解题思路:
注意事项: 太坑了, 题目说输入得字符串没有空格,那么就可以用scanf 读, 抱歉 依旧是错得;
另一个就是读入字符; 在读入字符之前,缓冲区还有上一个字符串读完之后,通过键盘键入的换行符, 如果不做处理,那么程序就是,直接把那个换行符读取,而不会读到你输入的字符;所以先要把缓冲区清理干净,在读入字符;因为上次读入之后,只留下了一个换行符;我们可以通过格式化输入scanf(“\n%c”)来进行读取输入的字符;
通常都是用; while(getchar() != '\n'); 注意有最后那个分号, 这种的比较通用,它能把缓冲区清理了,不知只清理一个字符。
不懂得留言; 谢谢;
参考代码:
#include <cstdio> #include <iostream> #include <cmath> #include <cstring> #include <string> #include <algorithm> using namespace std; int main() { char s[21], t[21], ch; gets(s); scanf("\n%c", &ch); int i = 0, j = 0; for(; i < strlen(s); ++i) { if(s[i] != ch) { t[j++] = s[i]; } } t[j] = '\0'; puts(t); return 0; }
0.0分
6 人评分
#include <stdio.h> #include <string.h> int main() { char ch[100]; char a; int n,i,b=0,c,d; char jiao; gets(ch); n=strlen(ch); scanf("%c",&a); for(i=0;i<n;i++) { if(ch[i]==a) { b++; for(c=i+1;c<n;c++) { jiao=ch[c]; ch[c]=ch[c-1]; ch[c-1]=jiao; } } } for(i=0;i<=n-b+1;i++) printf("%c",ch[i]); return 0; }
点我有惊喜!你懂得!浏览:1218 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1032 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:630 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:689 |
数组输出 (C语言代码)浏览:767 |
震宇大神的杀毒软件 (C++代码)浏览:1103 |
【出圈】 (C语言代码)浏览:553 |
不会做的浏览:870 |
【绝对值排序】 (C语言代码)浏览:819 |
DNA (C语言代码)浏览:389 |