L1-064 valuation of one hundred million of AI core code (20 point (s))
This question asks you to achieve a little bit more worth of questions and answers in English AI program, the rule is:
- No matter what users say, first of all they are saying as they are printed on one line;
- Eliminating redundant text spaces: a plurality of spaces between adjacent word into a space, to delete all lines leading and trailing spaces, the spaces in front of the punctuation deleted;
- The original text in all uppercase letters to lowercase, except
I
; - All the original separate
can you
,could you
correspondingly replacedI can
,I could
- where "independent" means that the word is separated spaces or punctuation; - The text of all independent
I
andme
replacedyou
; - All the original question marks
?
into exclamation points!
; - Outputting the alternative sentence in a row as AI answer.
Input formats:
Firstly, the first line of the input does not exceed a positive integer N 10, followed by N rows, each row of a given no more than 1000 characters, carriage return at the end of the user dialogue, non-empty string, comprising only letters, numbers, spaces, visible half-width punctuation.
Output formats:
According to the required output face problems, before each AI's answer to add AI:
a space.
Sample input:
6 Hello ? Good to chat with you can you speak Chinese? Really? Could you show me 5 What Is this prime? I,don 't know
Sample output:
Hello ? AI: hello! Good to chat with you AI: good to chat with you can you speak Chinese? AI: I can speak chinese! Really? AI: really! Could you show me 5 AI: I could show you 5 What Is this prime? I,don 't know AI: what Is this prime! you,don't know
Code:
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; getchar(); string s; while(n--){ string str[1005]; int cnt=0; getline(cin,s); cout << s << endl << "AI:"; for(int i=0;i<s.size();++i){ if(isalnum(s[i])) { IF (S [I] =! ' The I ' ) S [I] = tolower (S [I]) ; } the else { s.insert (I, ""); // before each non-alphanumeric spaces i ++ ; } IF (S [i] == ' ? ' ) S [i] = ' ! ' ; } ; stringstream SS (S) // spaces mainly rely on this function to cancel the word before the while (SS >> S) { STR [CNT ++] =S; } IF (! isalnum (str [0] [0]) ) // before the first position if the first word is then to output a punctuation space, answer questions in each of the requirements to add AI AI : and a space. << COUT " " ; for ( int I = 0 ; I <CNT; ++ I) { IF (! isalnum (STR [I] [0]) {) // determine whether the first character is punctuation, the front punctuation spaces do not output COUT << STR [I]; } the else IF (STR [I] == " CAN " && STR [I + . 1 ] == " you " cout << " I can"; i++; } else if(str[i]=="could" && str[i+1]=="you"){ cout << " I could"; i++; } else if(str[i]=="I" || str[i]=="me"){ cout << " you"; } else cout << " " << str[i]; } cout << endl; } }