C++ 输入错误的If语句

C++ 输入错误的If语句,c++,if-statement,C++,If Statement,程序不输入它假设要输入的if语句。例如,当第一个字符的语句1是oguzhan,而第二个字符是bugrahan时,它应该输入第一个if语句结尾替换应该是4,但它没有 #include <iostream> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <cmath> using namespace std; int main() { char

程序不输入它假设要输入的if语句。例如,当第一个字符的语句1是oguzhan,而第二个字符是bugrahan时,它应该输入第一个if语句结尾替换应该是4,但它没有

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cmath>

using namespace std;

int main() {
  char sentence1[50];
  char sentence2[50];
  int m, n, k, l;
  int i, j, substitution;
  cout << "Enter the first word:" << endl;
  cin >> sentence1;
  cout << "Enter the second word:" << endl;
  cin >> sentence2;
  m = strlen(sentence1);
  n = strlen(sentence2);
  int cost[m + 1][n + 1];
  cost[0][0] = 0;

  for (i = 1; i < m + 1; i++) {
    cost[i][0] = cost[i - 1][0] + 2;

  }
  for (j = 1; j < n + 1; j++) {
    cost[0][j] = cost[0][j - 1] + 2;

  }

  for (i = 1; i < m + 1; i++) {
    for (j = 1; j < n + 1; j++) {

      if ((sentence1[i - 1] == 'a' || sentence1[i - 1] == 'u' ||
           sentence1[i - 1] == 'e' || sentence1[i - 1] == 'i' ||
           sentence1[i - 1] == 'o') &&
          (sentence2[j - 1] != 'a' || sentence2[j - 1] != 'u' ||
           sentence2[j - 1] != 'e' || sentence2[j - 1] != 'i' ||
           sentence2[j - 1] != 'o')) {
        substitution = 4;
      }

      if ((sentence1[i - 1] != 'a' || sentence1[i - 1] != 'u' ||
           sentence1[i - 1] != 'e' || sentence1[i - 1] != 'i' ||
           sentence1[i - 1] != 'o') &&
          (sentence2[j - 1] == 'a' || sentence1[i - 1] != 'u' ||
           sentence1[i - 1] != 'e' || sentence1[i - 1] != 'i' ||
           sentence1[i - 1] != 'o')) {
        substitution = 4;
      }

      if (sentence1[i - 1] == sentence2[j - 1]) {
        substitution = 0;
      }

      if ((sentence1[i - 1] == 'a' || sentence1[i - 1] == 'u' ||
           sentence1[i - 1] == 'e' || sentence1[i - 1] == 'i' ||
           sentence1[i - 1] == 'o') &&
          (sentence2[j - 1] == 'a' || sentence2[j - 1] == 'u' ||
           sentence2[j - 1] == 'e' || sentence2[j - 1] == 'i' ||
           sentence2[j - 1] == 'o')) {
        substitution = 3;
      }
      if ((sentence1[i - 1] != 'a' || sentence1[i - 1] != 'u' ||
           sentence1[i - 1] != 'e' || sentence1[i - 1] != 'i' ||
           sentence1[i - 1] != 'o') &&
          (sentence2[j - 1] != 'a' || sentence2[j - 1] != 'u' ||
           sentence2[j - 1] != 'e' || sentence2[j - 1] != 'i' ||
           sentence2[j - 1] != 'o')) {
        substitution = 3;
      }

      cost[i][j] = min(min(cost[i - 1][j] + 2, cost[i][j - 1] + 2),
                       cost[i - 1][j - 1] + substitution);
    }
  }

  for (i = 0; i < m + 1; i++) {
    for (j = 0; j < n + 1; j++) {

      cout << cost[i][j] << "  ";
    }
    cout << endl;
  }

  cout << sentence1[0];
  return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
char语句1[50];
char语句2[50];
int m,n,k,l;
int i,j,替换;
cout语句1;
cout语句2;
m=斯特伦(第1句);
n=strlen(第2句);
国际成本[m+1][n+1];
成本[0][0]=0;
对于(i=1;i例如:
sentence2[j-1]!='A'| | sentence2[j-1]!='u'
这样的条件总是正确的——没有一个字符可以同时等于
A
u
,所以其中一个必须是正确的


如果您使用的是
!=
,则它几乎必须始终由
&&
连接,而不是
|
,否则无论输入如何,结果都将始终为真。

当它这样做时,您是否调试并查看了两者的值?另外,如果有人输入了超过49个字符怎么办?代码太多了。时间太少了。这应该如何工作?i是有效的C++ +代码> int成本[ M+1 ] [n+1 ],<代码> >你使用GPP吗?这(如果是一个字符不能同时是代码‘>’/代码>和‘代码’>U’< /代码>”,请考虑写(函数)<函数>代码> Boo-iSaaVoWell(Car C)。
一次,看看你的代码变得更小,更容易理解。(错误更少!)