#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char n[10003]={0};
while(cin>>n)
{long long sum=0;
if(n[0]<0){n[0]=-n[0];}
for(int i=0;i<10003;i++) {sum+=n[i];}
if(sum%3==0) cout<<"yes";
else cout<<"no";
cout<<endl;
}
return 0;
}
哪裡錯??????????
cin >> n
如果輸入-123
會變成
n[0] = '-'
n[1] = '1'
n[2] = '2'
n[3] = '3'
再想想怎麼做吧
cin >> n
如果輸入-123
會變成
n[0] = '-'
n[1] = '1'
n[2] = '2'
n[3] = '3'
再想想怎麼做吧
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char n[10003]={0};
while(cin>>n)
{long long sum=0;
if(n[0]=='-'){n[0]=0;}
for(int i=0;i<10003;i++) {sum+=n[i];}
if(sum%3==0) cout<<"yes";
else cout<<"no";
cout<<endl;
}
return 0;
}
請問這樣是哪個地方不對?