首页 > 学院 > 开发设计 > 正文

字符数组3

2019-11-08 00:54:29
字体:
来源:转载
供稿:网友

题目1:将字符串中的双引号换成单引号

#include<stdio.h>int main(){ int c, q = 1; while ((c = getchar()) != EOF) { if (c == '"') { PRintf("%s", q ? "'" : "'"); q = !q; } else printf("%c", c); } return 0;}

题目2:输出一个字符串的最小周期,如abcabc是以3为周期

#include<stdio.h>#include<string.h>int main(){ char Word[100]; scanf("%s", word); //不包括回车 '/n' int len = strlen(word); for (int i = 1; i <= len; i++) if (len % i == 0) //len的因子才能作为周期 { int ok = 1; for (int j = i; j < len; j++) //从周期后面的开始 if (word[j] != word[j%i]) { ok = 0; break; } if (ok) { printf("%d/n", i); break; } } return 0;}

额。。其实目的是表示一下可以用不同的方式输入一行字符串。


上一篇:文章标题

下一篇:算法训练 s01串

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表