View Code of Problem 22

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main (){
	char s1[1010], s2[1010], str[1010];
	while(cin >> s1 >> s2){
		int cnt = 0;
		for(int i = 0;i < strlen(s1);i++){
			for(int j = 0;j < strlen(s2);j++){
				if(s1[i]==s2[j]){
					str[cnt++] = s1[i];
					s2[j] = '#';
					break;
				}
			}
		}
		str[cnt] = 0;
		sort(str, str+cnt);
		put(str);
	}

	return 0;
}

/*
Main.cc: In function 'int main()':
Main.cc:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   for(int i = 0;i < strlen(s1);i++){
                 ~~^~~~~~~~~~~~
Main.cc:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
    for(int j = 0;j < strlen(s2);j++){
                  ~~^~~~~~~~~~~~
Main.cc:21:3: error: 'put' was not declared in this scope
   put(str);
   ^~~
Main.cc:21:3: note: suggested alternative: 'putw'
   put(str);
   ^~~
   putw
*/

Double click to view unformatted code.


Back to problem 22