输入字符串
#include <bits/stdc++.h>
using namespace std;
string solve(string s){
cout << "inside solve";
for(int i=0; i<s.length(); i++){
int occur=0;
while(i+1 < s.length()){
if(s[i] == s[i+1])
occur++;
}
if(occur%2!=0 && occur%3!=0 && occur%5!=0)
return "no";
}
cout << "inside solve";
return "yes";
}
int main(){
ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
int tc;
cin >> tc;
//cout << tc;
while(tc--){
string s;
cin >> s;
//cout << "Inside main's while";
cout << solve(s);
}
return 0;
}
在输入字符串后,在我的主要功能中,什么都没发生。使用cin&gt;&gt;是否存在一些问题s。同样,当我不征写cin.tie(0)时; cout.tie(0); 循环也不会进入室内。那怎么了?
#include <bits/stdc++.h>
using namespace std;
string solve(string s){
cout << "inside solve";
for(int i=0; i<s.length(); i++){
int occur=0;
while(i+1 < s.length()){
if(s[i] == s[i+1])
occur++;
}
if(occur%2!=0 && occur%3!=0 && occur%5!=0)
return "no";
}
cout << "inside solve";
return "yes";
}
int main(){
ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
int tc;
cin >> tc;
//cout << tc;
while(tc--){
string s;
cin >> s;
//cout << "Inside main's while";
cout << solve(s);
}
return 0;
}
In my main function after I'm inputting the string nothing is happening. Is there some problem in using cin >> s. Also when I'm uncommenting the line cin.tie(0); cout.tie(0);
It is not going inside while loop too. So what is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里有一个无尽的循环:
“我”在LOPP中没有修改。循环将永远运行。条件始终是正确的。
使用第二个变量k = i+1,在段循环中进行此操作,然后将s [i]与s [k ++]进行比较。
不要继续与这些所谓的“竞争方面”合作
You have an endless loop here:
'i' is not modified in the lopp. The loop will run forever. The condition is always true.
Use a second variable k=i+1, take this in the while loop and compare s[i] with s[k++].
Do not continue to work with these so called 'competition sides'