我不知道该怎么办? [英] i dont know what should i do?

查看:70
本文介绍了我不知道该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// samakhano0m.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
	int n , m ;
	int i = 0 , j = 0 ;
	
	cout << " Enter the lengh of string1 " << endl ;
	cin >> n ;
	cout << " Enter the lengh of string2 " << endl ;
	cin >> m ;
	char A[100];       char B[100];
	cout << "Enter the string1 : " << endl ;
	for( int j = 0 ; j < n ; j++ ){
	     cin >> A[j] ;
	}
	
	cout << "Enter the string2 : " << endl ;
	for( int i = 0 ; i < m ; i++ ){
	    cin >> B[i] ;
	}
	i=0;   j=0;   int r=0;
		for (j = 0;j< n-1 ;j++ )
			{
				if( B[i] == A[j] )
				{
					r++ ;
					if (i=m-1){
						i=0;
					}
					i++;
				}
				
				else
				{
					i = 0 ;
				}
		
		}
	cout << (r/m);
	
	
	return 0 ;
}


该程序比较2个字符串
a = xxxxxxyx
b = xy
但这不是吗?


this program compare 2 string
a= xxxxxxyx
b=xy
but it does not ?

推荐答案

这显然是一个家庭作业问题,即使不是,学生也只需要5分钟的书写笔就可以知道是什么.发生在这里:
It''s clearly a homework question, even if not, a student would simply needs a 5 minute copy-pen to see what is happening here:
while( j < n )
{
  for( int i = 0 ; i < m ;  )
     for( int j = 0 ; j < n ; )
	if( B == A )
	{
	    i++ ;
	    cout << "yay"  ;
	}
	else
	{
            j++ ;
	}
}


很清楚这里发生了什么.您不需要运行的环境即可查看/调试以查找问题和实现.此外,如果可以的话,为什么不自己编写一个新的而不是进行更正呢.我在这里看到很多问题...从头开始,如果两个字符串的长度不同,还有什么要比较的?


It''s pretty clear on what is happening here. You don''t need a running environment to see/debug to find the issue and implementation. Further, why not write a new one by yourself instead of correcting it, if you have that option. I see lots of issues here... starting with, if two string lengths are different what is left to be compared?


该代码中有很多错误,我''我只能解决循环问题:

There''s a ton of errors in that code, I''ll only address the loop:

while( j < n )
{
  for( int i = 0 ; i < m ;  ) //<-- No brackets
    for( int j = 0 ; j < n ; ) //<-- No brackets 
      if( B == A ) //<-- Comparing pointers, not characters, in no way using indexes (so loops are worthless anyway)
      {
	i++ ;
	cout << "yay"  ;
      }
      else
      {
	j++ ;
      }
}


如何不在这个论坛上充斥问题,而是着手做一件事,然后实际工作,阅读您的源材料,阅读在线文章,并尝试学习C ++而不是尝试让我们为您修复所有问题?
How about not flooding this forum with questions, instead working on one thing, and actually working, reading your source material, reading online articles, and trying to learn C++ instead of trying to get us to fix it all for you ?


这篇关于我不知道该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆