4 条题解
-
6
题前吐槽
UPD [2022/9/22 20:16] 修改了一下错误的, 注释忘删了删了。
这个题好垃圾啊,乍一看好少人AC,其实就是一个比第一题还简单的模拟!!! 居然没有人写题解
太简单了!!!!!
这么明显的做法,很难想象只有17人过。
给个好评吧~
题解
这道题没说清楚,其实像什么连接符都是对的,你只需要判断验证码对不对就行了,不对改一下输出。 所以思路简单清楚,就是先把几个数都存到数组里,然后一个循环算完 , 之后转成字符 和输入的验证码比较。即使没有想到数组也可以手动加。 总结来说这题就是暴力,或者比暴力还低级。
#include <bits/stdc++.h> using namespace std; string id; int dat[10], ans = 0; char st; // 这题其实很明显 // x-xxx-xxxxx-x // 0 234 6789| 12 // 10 int main() { cin >> id; // cin输入字符串 dat[0] = id[0] - '0'; // 可以用数组把不连续的下标转换成连续的 dat[1] = id[2] - '0'; dat[2] = id[3] - '0'; dat[3] = id[4] - '0'; dat[4] = id[6] - '0'; dat[5] = id[7] - '0'; dat[6] = id[8] - '0'; dat[7] = id[9] - '0'; dat[8] = id[10] - '0'; for (int i = 1; i <= 9; i++) // 循环 { ans += dat[i - 1] * i; // 根据验证码的计算方法计算 } // 接下来计算st,为什么要计算st,因为还有X一个讨厌的东西,不能转成int比那就char比 if (ans % 11 == 10) st = 'X'; // 10 -> X else st = ans % 11 + '0'; if (id[12] == st) // 正确 printf("Right\n"); else { id[12] = st; // 改一下 printf("%s\n", id.c_str()); // 输出 } return 0; }
这么明显的做法,就算想不到用数组,也可以直接用 ,或者数组预处理数字的位置。
int pos[] = {0, 2, 3, 4, 6, 7, 8, 9, 10}; int stpos = 12;
#include <bits/stdc++.h> using namespace std; string id; int dat[10], ans = 0; char st; int main() { cin >> id; dat[0] = id[0] - '0'; dat[1] = id[2] - '0'; dat[2] = id[3] - '0'; dat[3] = id[4] - '0'; dat[4] = id[6] - '0'; dat[5] = id[7] - '0'; dat[6] = id[8] - '0'; dat[7] = id[9] - '0'; dat[8] = id[10] - '0'; for (int i = 1; i <= 9; i++) { ans += dat[i - 1] * i; } if (ans % 11 == 10) st = 'X'; else st = ans % 11 + '0'; if (id[12] == st) printf("Right\n"); else { id[12] = st; printf("%s\n", id.c_str()); } return 0; }
-
1
前一个人去掉注释34行…… 我这个少点,不知道那个人怎么想的…… 用10个变量存……
#include <bits/stdc++.h> // 万能头文件 using namespace std; char a[1005]; int lena, now, ans; int main() { scanf("%s", a); for (int i = 0; i < 11; i++) // 计算数值 { if (a[i] == '-') continue; int w = a[i] - '0'; ++now; ans += w * now; } ans %= 11; if (ans == a[12] - '0' || (ans == 10 && a[12] == 'X')) // 正确 printf("Right"); else { for (int i = 0; i < 11; i++) // 前11个字符是不用更改的 printf("%c", a[i]); if (ans == 10) // 因为是%11,所以会出现10的情况 printf("-X"); else printf("-%d", ans); } return 0; }
-
-1
我的应该比较好理解,就是有点烦😄,希望对大家有所帮助👀️
string x, n, m; int sum, a[100]; int main() { cin >> x; int num = 0; for (int i = 0; i < 13; i++) { if (x[i] >= '0' && x[i] <= '9') { a[++num] = x[i] - '0'; } } for (int i = 1; i <= 9; i++) { sum += i * a[i]; } int ans = sum % 11; if (ans > 10 || ans == 10) { n = 'X'; } else { n = ans + '0'; } m = x[12]; if (m == n) { cout << "Right"; } else { for (int i = 0; i < 12; i++) { cout << x[i]; } cout << n; } return 0; }
-
-2
前两个为什么这么逊呀👎
#include <bits/stdc++.h> using namespace std; int main() { int z,b,c,i,ans=0; char d,f,g,x; cin>>z>>d>>b>>f>>c>>g>>x; ans=(z*1+b/100*2+b/10%10*3+b%10*4+c/10000*5+c/1000%10*6+c/100%10*7+c/10%10*8+c%10*9)%11; if(x=='X') i=10; else i=int(x)-48; if(i==ans) cout<<"Right"; else { if(ans==10) cout<<z<<d<<b<<f<<c<<g<<"X"; else cout<<z<<d<<b<<f<<c<<g<<ans; } return 0; }
- 1
信息
- ID
- 794
- 时间
- 1000ms
- 内存
- 50MiB
- 难度
- 6
- 标签
- 递交数
- 512
- 已通过
- 151
- 上传者