1
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n;
cin>>n;
int x=0;
while(n--)
{
char s[3];
cin>>s;
if(strcmp(s,"X++")==0||strcmp(s,"++X")==0)
x+=1;
else
x-=1;
}
cout<<x;
}
if文の中でstrcmp行を削除したときに、ループが正常に機能しました。ループが1回実行した直後に終了するのはなぜですか?
'「X ++」'、あなたのための 'のstd :: STRING'代わりの文字列を使用しないで、なぜあなたはC++を使用しているので、' S'はサイズ4 –
の少なくともでなければならないような文字列を格納します入力。比較はまた、 'if(s ==" X ++ "|| ...' –