#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string str[110];
char Z[11]={'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
int Weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int N, i, j;
vector<string>V;
while( cin>>N )
{
for( i=0; i<N; i++ )
cin>>str[i];
V.clear();
int sum,ans=0;
for( i=0; i<N; i++ )
{
sum=0;
for( j=0; j<17; j++ )
{
if( str[i][j]<'0' || str[i][j]>'9' )
break;
else
sum+=(str[i][j]-'0')*Weight[j];
}
if( j==17 )
{
//cout<<str[i][j]<<" "<<sum%11<<' '<<Z[sum%11]<<endl;
if( str[i][j]==Z[sum%11] )
{
ans++;
}
else
V.push_back(str[i]);
}
else
V.push_back(str[i]);
}
if(ans==N)
cout<<"All passed"<<endl;
else
for( int i=0; i<V.size(); i++ )
cout<<V[i]<<endl;
}
return 0;
}
思路很清晰:
输入 到字符串数组
遍历数组 合法的 ans++
不合法的 push_back到vector
最后根据ans的值判断 后 输出结果
_____________________________________________随便写写_____________________________________
嗯 天边飘来一朵美丽的云
天空湛蓝
云儿舒展
杨树挺拔
我
在机房
努力