int emailusp( const char * email) {
/* Pega o tamanho total do e-mail digitado. */
/* Se for muito curto, cai fora retornando 0. */
if ( tamanho < 7 ) return 0 ;
const char verifica[ 7 ] = "@usp.br" ;
/* Verifica se cada um dos últimos caracteres é "@usp.br". Se encontrar um que não é, retorna 0. */
int i;
for ( i = 0 ; i < 7 ; i++ ) {
if ( email[ tamanho - 7 + i] != verifica[ i] ) return 0 ;
}
/* Os os últimos caracteres são "@usp.br". Retorna 1. */
return 1 ;
}
void testar( const char * email) {
int valido = emailusp( email) ;
printf ( "%s%s eh um e-mail da USP.\n " , email
, valido
? "" : " nao" ) ; }
int main( ) {
testar( "verde@usp.br" ) ;
testar( "azul@usp.br" ) ;
testar( "amarelo@gmail.com" ) ;
testar( "vermelho@upp.br" ) ;
testar( "a@a" ) ;
}
aW50IGVtYWlsdXNwKGNvbnN0IGNoYXIgKmVtYWlsKSB7CgogICAgLyogUGVnYSBvIHRhbWFuaG8gdG90YWwgZG8gZS1tYWlsIGRpZ2l0YWRvLiAqLwogICAgaW50IHRhbWFuaG8gPSBzdHJsZW4oZW1haWwpOwoKICAgIC8qIFNlIGZvciBtdWl0byBjdXJ0bywgY2FpIGZvcmEgcmV0b3JuYW5kbyAwLiAqLwogICAgaWYgKHRhbWFuaG8gPCA3KSByZXR1cm4gMDsKCiAgICBjb25zdCBjaGFyIHZlcmlmaWNhWzddID0gIkB1c3AuYnIiOwoKICAgIC8qIFZlcmlmaWNhIHNlIGNhZGEgdW0gZG9zIMO6bHRpbW9zIGNhcmFjdGVyZXMgw6kgIkB1c3AuYnIiLiBTZSBlbmNvbnRyYXIgdW0gcXVlIG7Do28gw6ksIHJldG9ybmEgMC4gKi8KICAgIGludCBpOwogICAgZm9yIChpID0gMDsgaSA8IDc7IGkrKykgewogICAgICAgIGlmIChlbWFpbFt0YW1hbmhvIC0gNyArIGldICE9IHZlcmlmaWNhW2ldKSByZXR1cm4gMDsKICAgIH0KCiAgICAvKiBPcyBvcyDDumx0aW1vcyBjYXJhY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