不懂就问,为什么这段声明放在外面能过!!
查看原帖
不懂就问,为什么这段声明放在外面能过!!
1217330
xdedb楼主2023/12/20 19:44

就是对于string和int类的声明,放在函数里面过不了全WA,但是放在main外面就能过。现在展示的这一段是全WA的

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main(){
    int ans;
    string str;
    while(cin>>str){
        for(int i=0;i<str.size();i++){
            if(str[i]>='a' && str[i]<='z') {ans++;continue;}
            if(str[i]>='A' && str[i]<='Z') {ans++;continue;}
            if(str[i]>='0' && str[i]<='9') ans++;
        }
    }
    cout<<ans;
}
2023/12/20 19:44
加载中...