1 条题解
-
0
P76001 逐字校对 — 题解
专题: 字符串
适用题目: 新生 OJ 本地题包中的 P76001,不要直接用于外站同名题。解题思路
逐位与固定单词
algorithm比较,每个位置不同就让计数器加一。复杂度
时间 ,额外空间 。
易错点
不要用整串是否相等代替逐位统计。
C11 参考程序
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <limits.h> int main(void) { char s[32]; scanf("%31s", s); const char *t = "algorithm"; int ans = 0; for (int i = 0; i < 9; i++) if (s[i] != t[i]) ans++; printf("%d\n", ans); return 0; }C++17 参考程序
#include <bits/stdc++.h> using namespace std; using ll = long long; #define nl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s,t="algorithm"; cin>>s; int ans=0; for(int i=0;i<9;i++)ans+=(s[i]!=t[i]); cout<<ans<<nl; return 0; }
题解建议设置为训练结束后开放。普通判题无法验证是否实际使用指定函数或 STL。
- 1
信息
- ID
- 1770
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 提交数
- 3
- 已通过
- 2
- 上传者