pat-1120

#include<iostream>
#include<string>
#include<set>
using namespace std;
int main(){
	int n;
	string temp;
	cin>>n;
	set<int> ans;
	for(int i=0;i<n;i++){
		cin>>temp;
		int sum=0;
		for(int j=0;j<temp.size();j++){
			string temp1=temp.substr(j,1);
			sum+=stoi(temp1);
		}
		ans.insert(sum);
	}
	printf("%d\n",ans.size());
	for(auto it=ans.begin();it!=ans.end();it++){
		if(it!=ans.begin()) printf(" ");
		printf("%d",*it);
	}
	return 0;
}

 to sum up

1. stoi() if the string type in the parentheses is a string, the string type cannot be a char type

2. Set is the first choice when the output of the question is different and does not repeat, and the data is arranged from small to large

3. I forgot cin>>n again, and read it again at the end to prevent me from not knowing where to look when making mistakes.

English

 

Question Summarize the type of data and the type of output required

 

 

 

Guess you like

Origin blog.csdn.net/m0_45359314/article/details/113091083