并夕夕输入法
by K_Madoka @ 2019-04-10 21:05:36
希望更丰富的展现?使用Mark♂down
by aminoas @ 2019-04-10 21:09:07
首先 **希望更丰富的展现?[使用Markdown](https://www.luogu.org/wiki/show?name=%E5%B8%AE%E5%8A%A9%EF%BC%9Amarkdown)**, 帮你贴下代码顺便人工格式化一下...
```cpp
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
char str[100];
int mul[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int num[10];
int len = -1;
int n = -1;
char bo;
while ((str[++len] = getchar()) != '\n') {
if (str[len] != '-') {
num[++n] = str[len] - '0';
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans += num[i] * mul[i];
}
ans = ans % 11;
if (ans == 10) {
bo = 'X';
}
else {
bo = ans + '0';
}
if (bo == str[len - 1]) {
cout << "Right";
}
else {
for(int i = 0; i < len - 1; i++) {
cout << str[i];
}
cout << bo;
}
return 0;
}
```
然后就可以找问题了, 先看第一个while输入的地方, 这里判断输入结束的标志是\n, 但是注意读入是\r\n换行, 那把\r读入了肯定就不对了. 然后读入的时候没有处理X? 然后mul是不是少了一项?
by Alex_Cui @ 2019-04-11 12:04:36