50分!求助!

P2955 [USACO09OCT] Even? Odd? G

wow a[i]是int型 这题考的是字符串
by 腾昊一世 @ 2017-09-16 16:35:38


```cpp #include<stdio.h> #include<string.h> int main(){ char str1[101][101]; int a,i,c[100]; scanf("%d",&a); for(i=1;i<=a;i++){ scanf("%s",str1[i]); c[i]=str1[i][strlen(str1[i])-1]-'0'; if(c[i]%2==1) printf("odd"); else if(c[i]%2==0) printf("even"); if(i!=a) printf("\n"); } } ```
by 腾昊一世 @ 2017-09-16 16:36:29


以前的代码,不优秀
by 腾昊一世 @ 2017-09-16 16:37:33


用string方便些。。。 ```cpp #include<iostream> #include<cstring> using namespace std; int main() { int n; string s; cin>>n; for(int i=0;i<n;i++) { cin>>s; if(s[s.size() -1]%2==1) cout<<"odd"<<endl; if(s[s.size() -1]%2==0) cout<<"even"<<endl; } return 0; } ```
by partychicken @ 2017-09-20 13:12:45


谢谢!
by 无欢 @ 2017-10-12 13:52:00


```cpp #include <bits/stdc++.h> using namespace std; int main(){ int n; string s; cin>>n; while(cin>>s){ n=s.size(); if(!(s[n-1]%2)) cout<<"even"<<endl; else cout<<"odd"<<endl; } return 0; } 简单点 ```
by OuRiGe @ 2017-10-29 15:37:19


```cpp #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { string k; cin>>k; if(int(k[k.size()-1])%2==0) cout<<"even"<<endl; else cout<<"odd"<<endl; } return 0; } ```
by 风格雨关 @ 2017-12-23 14:15:31


|