gpt4 book ai didi

c++ - 为什么此C++程序不打印任何内容?

转载 作者:行者123 更新时间:2023-12-01 14:57:04 25 4
gpt4 key购买 nike

I have this C++ program but its not printing anything in the console.I am copying the content of the string in 2 vectors and doing count increment operations on them.

#include <iostream>
#include<vector>
#include<bits/stdc++.h>
#include<string>
using namespace std;

int main()
{
string s;
cin>>s;
int i,j;
vector<char> a;
vector<char> b;
int count1=0;
int count2=0;
int count3=0;
int t=s.length()/2;
for(i=0;i<t-1;t++)
{
a.push_back(s[i]);
}
for(j=t;j<s.length();j++)
{
b.push_back(s[j]);
}
int e1,e2;
for (auto it1 = a.begin(), it2 = b.begin();
it1 != a.end() && it2 != b.end();
++it1, ++it2)
{
if(int(*it1)>int(*it2))
count1++;

if(int(*it1)<int(*it2))
count2++;

if(int(*it1)==int(*it2))
count3++;
}

cout<<min(min(count1,count2),count3);
}

I am printing the minimum of the three counts in the end.

最佳答案

我发现您的代码在下面陷入无限循环。

for (i = 0; i < t - 1; t++)   // not t++, but it should be i++
{
a.push_back(s[i]);
}
我也相信调试技能可以帮助您在程序中发现错误。

关于c++ - 为什么此C++程序不打印任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63647202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com