日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c++ 字符串

發布時間:2025/3/15 c/c++ 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++ 字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*

一個合法的身份證號碼由17位地區、日期編號和順序編號加1位校驗碼組成。校驗碼的計算規則如下:

首先對前17位數字加權求和,權重分配為:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后將計算的和對11取模得

到值Z;最后按照以下關系對應Z值與校驗碼M的值:

Z:0 1 2 3 4 5 6 7 8 9 10

M:1 0 X 9 8 7 6 5 4 3 2

現在給定一些身份證號碼,請你驗證校驗碼的有效性,并輸出有問題的號碼。

輸入描述:

輸入第一行給出正整數N(<= 100)是輸入的身份證號碼的個數。隨后N行,每行給出1個18位身份證號碼。

輸出描述:

按照輸入的順序每行輸出1個有問題的身份證號碼。這里并不檢驗前17位是否合理,只檢查前17位是否全為數字且最后1位校驗碼計算準確。如果所有號碼都正常,

則輸出“All passed”。

解題思路:分割字符串


輸入例子:

4

320124198808240056

12010X198901011234

110108196711301866

37070419881216001X
*/
#include <iostream>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
int quan[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char mo[11]={'1','0','x','9','8','7','6','5','4','3','2'};
bool isdigit_str(const string str){
??? int count=0;
??? for(int i=0;i<str.length();i++){
??????? if(isdigit(str[i])) count++;
??? }
??? if(count==str.length())return true;
??? else return false;
}
char qu_mo(const string str){
??? int sum=0;
??? for(int i=0;i<str.length();i++){
??????? int temp = str[i]-'0';
??????? sum+=temp*quan[i];
??? }
??? sum=sum%11;
??? return mo[sum];
}
int main()
{
??? int N;
??? int count=0;
??? cin>>N;
??? vector<string> res;
??? for(int i=0;i<N;i++){
??????? string str;
??????? cin>>str;
??????? string str2=str.substr(0,17);
??????? if(isdigit_str(str2)){
??????????? if(qu_mo(str2)==str[17]) count++;
??????????? else res.push_back(str);
??????? }else res.push_back(str);
??? }
??? if(count==N)cout<<"All passed"<<endl;
??? else for(vector<string>::iterator it=res.begin();it!=res.end();it++){
??????????? cout<<*it<<endl;
??? }
?? ?return 0;
}

轉載于:https://www.cnblogs.com/qingtianBKY/p/6758905.html

總結

以上是生活随笔為你收集整理的c++ 字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。