#include<iostream> using namespace std; int main() { int T[100];//用于确认所有身分是否都正确 int N;//输入的身份证的个数 cin >> N; int a = 0; char A[100][18];//储存输入的身份证号 //首先将z值和校验码m的值对应起来 int Z[17] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char M[11] = { '1','0','X','9','8','7','6','5','4','3','2' }; //进行统一的输入 for (int i = 0; i < N; i++) { for (int j = 0; j < 18; j++) { cin >> A[i][j]; } } while (a < N) { char n;//最后的校验值 int sum = 0; //检验是否都为数字 int q = 1;//确认是否都为数字 for (int i = 0; i < 17; i++) { if (A[a][i] - '0' < 0 || A[a][i] - '0' > 9) { q = 0; } } //不符合条件输出 if (q == 0) { T[a] = 1; for (int i = 0; i < 18; i++) { cout << A[a][i]; } cout << endl; } //加权求和 else { for (int i = 0; i < 17; i++) { sum += (A[a][i] - '0') * Z[i]; } n = M[sum % 11]; if (n == A[a][17]) { T[a] = 0; } else { T[a] = 1; for (int i = 0; i < 18; i++) { cout << A[a][i]; } cout << endl; } } a++; if (T == 0) cout << "All passed" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string s; double sum=100; int count=0; bool flag=false; cin>>s; int n=s.length(); for(int i=0;i<n;i++) { char c=s.at(i); if(c=='-') { sum*=1.5; flag=true; } else{ if(c=='2') { count++; } if(i==n-1&&(c-'0')%2==0) { sum*=2; } } } if(flag) { sum=sum*count/(n-1); } else{ sum=sum*count/n; } cout<<setiosflags(ios::fixed)<<setprecision(2)<<sum<<"%";//c++保留两位小数的方法 }
标签:7.16,int,18,cin,char,++,100 From: https://www.cnblogs.com/xuxingkai/p/17558736.html