1143:最长最短单词

字符串处理

#include<bits/stdc++.h>
using namespace std;
int main(){
	char c[20050];
	int l,a=0,big=0,x,x2,small=9999;
	cin.getline(c,20050);
	l=strlen(c);
	c[l]=' ';
	c[l+1]='\0';
	for(int i=0;i<=l;i++) if(c[i]==',') c[i]==' ';
	for(int i=0;i<=l;i++){
		if(c[i]!=' '&&c[i]!=',')
			a++;
		else {
			if(a>big) {big=a;x=i;}
			if(a<small) {small=a;x2=i;}
			a=0;
		}
	}
	for(int i=x-big;i<x;i++){
		cout<<c[i];
	}
	cout<<endl;
	for(int i=x2-small;i<x2;i++){
		cout<<c[i];
	}
	return 0;
}