-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrect-capitalisation.c
143 lines (79 loc) · 3.46 KB
/
correct-capitalisation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*[22 marks]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Automated Grading Scheme:
Visible: 2 marks for each visible test case.
Hidden: 4 marks for hidden test case 1, 2, 5 and 3 marks for hidden test case 3, 4.
Manually Grading Scheme:
Note: Give 0 marks for test-case component if there is any form of hard-coding. Eg: printf("0");
Penalty :
-20% for using strings, arrays, or array indexing to solve this problem,or any future concepts
-20% each for using any library function (string library) other than printf and scanf
-20% each for using any library other than stdio.h
----------------------------------------------------------------------
Problem Description
You are given a passage. There are mistakes regarding which words should begin with capital letters in the passage. For instance, in the following passage, the first letter of the second sentence begins with a lowercase letter: "This course is Fundamentals of Computing. we hope you enjoy it!" You have to write to a program to take a passage as input and print the corrected version, with the following rule:
The first letter of each sentence in the corrected version begins with a capital letter.
Note that the input will obey the following rules:
The first letter of each sentence will always begin with either a lowercase or uppercase letter.
Each sentence can end with either of the following 3 punctuation marks: '.', '?', '!'.
There is a whitespace character after each sentence, except the last one.
Constraints
You are not allowed to use strings, arrays, or array indexing to solve this problem, you can only scan the input character by character. You are not allowed to use any string library functions for checking if a character is lowercase or uppercase.
Input:
The first line contains an integer specifying the number of the sentence in the input.
The second line contains the passage. Note that there are new newline characters in the passage.
Output:
Your program should print the correct version of the passage according to the rules specified above.
Sample Test Cases
Test Case 1
Input:
2
This is already a correct sentence. No change is required.
Output:
This is already a correct sentence. No change is required.
Explanation: The above input already obeys the rule we had, hence the output is the same as the input.
Test Case 2
Input:
2
the first sentence itself begins with a lowercase letter. It should be capitalized.
Output:
The first sentence itself begins with a lowercase letter. It should be capitalized.
Explanation: As mentioned in the rules the first letter of each sentence should begin with an uppercase letter. Hence, "the" should be transformed to the "The".*/
// solution:
#include <stdio.h>
int main()
{
int n;
char c;
scanf("%d", &n);
getchar();
for (int i = 1; i <= n; i++)
{
scanf("%c", &c);
if (c <= 'z' && c >= 'a')
{
c = c - 'a' + 'A';
}
printf("%c", c);
scanf("%c", &c);
while (1)
{
if (c == '.' || c == '!' || c == '?')
{
printf("%c", c);
break;
}
else
{
printf("%c", c);
}
scanf("%c", &c);
}
if (i < n)
{
printf(" ");
getchar();
}
}
return 0;
}